diff options
| author | Maxime Coste <mawww@kakoune.org> | 2022-07-13 12:24:14 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2022-07-13 12:24:14 +1000 |
| commit | c7fbf1f3905f77f136e898479352e590787434d2 (patch) | |
| tree | 190edecbc65bac3c2e03a53b62056b3a981cd90a /src | |
| parent | 195fe8fd29a1824372ff69e6ef8b8e5be8bc9a07 (diff) | |
Re-work line trimming to fix issues with column highighters
Instead of triming only buffer ranges, add a trim_from method to
display line to keep the initial N columns, we know how many columns
are used by non-trimable widgets in DisplaySetup::widget_columns so
we can just pass this.
Also restore the previous logic for face merging
Fixes #4670
Diffstat (limited to 'src')
| -rw-r--r-- | src/display_buffer.cc | 34 | ||||
| -rw-r--r-- | src/display_buffer.hh | 8 | ||||
| -rw-r--r-- | src/face.hh | 4 | ||||
| -rw-r--r-- | src/highlighters.cc | 26 | ||||
| -rw-r--r-- | src/window.cc | 2 |
5 files changed, 39 insertions, 35 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 2b377310..335fb5de 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -193,29 +193,45 @@ ColumnCount DisplayLine::length() const return len; } -bool DisplayLine::trim(ColumnCount first_col, ColumnCount col_count, bool only_buffer) +bool DisplayLine::trim(ColumnCount front, ColumnCount col_count) { - for (auto it = begin(); first_col > 0 and it != end(); ) + return trim_from(0_col, front, col_count); +} + +bool DisplayLine::trim_from(ColumnCount first_col, ColumnCount front, ColumnCount col_count) +{ + auto it = begin(); + while (first_col > 0 and it != end()) { - if (only_buffer and !it->has_buffer_range()) + auto len = it->length(); + if (len <= first_col) { ++it; - continue; + first_col -= len; } + else + { + it = ++split(it, front); + first_col = 0; + } + } + while (front > 0 and it != end()) + { auto len = it->length(); - if (len <= first_col) + if (len <= front) { m_atoms.erase(it); - first_col -= len; + front -= len; } else { - it->trim_begin(first_col); - first_col = 0; + it->trim_begin(front); + front = 0; } } - auto it = begin(); + + it = begin(); for (; it != end() and col_count > 0; ++it) col_count -= it->length(); diff --git a/src/display_buffer.hh b/src/display_buffer.hh index af37b18f..8008f86a 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -144,9 +144,13 @@ public: iterator erase(iterator beg, iterator end); DisplayAtom& push_back(DisplayAtom atom); - // remove first_col from the begining of the line, and make sure + // remove front from the begining of the line, and make sure // the line is less that col_count character - bool trim(ColumnCount first_col, ColumnCount col_count, bool only_buffer = false); + bool trim(ColumnCount front, ColumnCount col_count); + + // remove front from the begining of the line + first_col, and make sure + // the line is less that col_count character + bool trim_from(ColumnCount first_col, ColumnCount front, ColumnCount col_count); // Merge together consecutive atoms sharing the same display attributes void optimize(); diff --git a/src/face.hh b/src/face.hh index e1047bcd..ce544116 100644 --- a/src/face.hh +++ b/src/face.hh @@ -65,10 +65,10 @@ inline Face merge_faces(const Face& base, const Face& face) }; auto choose = [&](Color Face::*color, Attribute final_attr) { - if (base.attributes & final_attr) - return base.*color; if (face.attributes & final_attr) return face.*color; + if (base.attributes & final_attr) + return base.*color; if (face.*color == Color::Default) return base.*color; if ((base.*color).isRGB() and (face.*color).isRGB() and (face.*color).a != 255) diff --git a/src/highlighters.cc b/src/highlighters.cc index 5245b3c6..4b9540b6 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -558,17 +558,6 @@ std::unique_ptr<Highlighter> create_dynamic_regex_highlighter(HighlighterParamet return make_hl(get_regex, get_face); } -namespace -{ - -Face make_final(Face face) -{ - face.attributes |= Attribute::Final; - return face; -} - -} - const HighlighterDesc line_desc = { "Parameters: <value string> <face>\n" "Highlight the line given by evaluating <value string> with <face>", @@ -615,7 +604,7 @@ std::unique_ptr<Highlighter> create_line_highlighter(HighlighterParameters param } const ColumnCount remaining = context.context.window().dimensions().column - column; if (remaining > 0) - it->push_back({ String{' ', remaining}, make_final(face) }); + it->push_back({String{' ', remaining}, face}); }; return make_highlighter(std::move(func)); @@ -652,18 +641,13 @@ std::unique_ptr<Highlighter> create_column_highlighter(HighlighterParameters par if (column < context.setup.first_column or column >= context.setup.first_column + context.context.window().dimensions().column) return; - const Buffer& buffer = context.context.buffer(); + column += context.setup.widget_columns; for (auto& line : display_buffer.lines()) { auto remaining_col = column; bool found = false; - auto first_buf = find_if(line, [](auto& atom) { return atom.has_buffer_range(); }); - BufferCoord last_pos{}; - for (auto atom_it = first_buf; atom_it != line.end(); ++atom_it) + for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it) { - if (atom_it->has_buffer_range()) - last_pos = atom_it->end(); - const auto atom_len = atom_it->length(); if (remaining_col < atom_len) { @@ -681,8 +665,8 @@ std::unique_ptr<Highlighter> create_column_highlighter(HighlighterParameters par continue; if (remaining_col > 0) - line.push_back({buffer, last_pos, last_pos, String{' ', remaining_col}, make_final(Face{})}); - line.push_back({buffer, last_pos, last_pos, " ", make_final(face)}); + line.push_back({String{' ', remaining_col}, Face{}}); + line.push_back({" ", face}); } }; diff --git a/src/window.cc b/src/window.cc index 47bf65bd..455e6a2d 100644 --- a/src/window.cc +++ b/src/window.cc @@ -159,7 +159,7 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) m_builtin_highlighters.highlight({context, setup, pass, {}}, m_display_buffer, range); for (auto& line : m_display_buffer.lines()) - line.trim(setup.first_column, m_dimensions.column, true); + line.trim_from(setup.widget_columns, setup.first_column, m_dimensions.column); m_display_buffer.optimize(); |
