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(); ) - { - if (only_buffer and !it->has_buffer_range()) - { - ++it; - continue; - } + 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()) + { auto len = it->length(); if (len <= first_col) { - m_atoms.erase(it); + ++it; first_col -= len; } else { - it->trim_begin(first_col); + it = ++split(it, front); first_col = 0; } } - auto it = begin(); + + while (front > 0 and it != end()) + { + auto len = it->length(); + if (len <= front) + { + m_atoms.erase(it); + front -= len; + } + else + { + it->trim_begin(front); + front = 0; + } + } + + 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 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: \n" "Highlight the line given by evaluating with ", @@ -615,7 +604,7 @@ std::unique_ptr 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 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 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(); diff --git a/test/highlight/column/multi-columns/script b/test/highlight/column/multi-columns/script index 67e93c53..9990c809 100644 --- a/test/highlight/column/multi-columns/script +++ b/test/highlight/column/multi-columns/script @@ -1,2 +1,2 @@ ui_out -ignore 1 -ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 1│" }, { "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 2│" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "b" }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": [] }, "contents": "\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 3│" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "ab" }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": "c" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 4│" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "ab" }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": "c" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "d" }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' +ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 1│" }, { "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 2│" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "b" }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": [] }, "contents": "\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 3│" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "ab" }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": "c" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " 4│" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "ab" }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": "c" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "d" }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "green", "underline": "default", "attributes": [] }, "contents": " " }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' diff --git a/test/regression/1382-column-highlighter-broken-on-horizontal-scroll/script b/test/regression/1382-column-highlighter-broken-on-horizontal-scroll/script index 60940766..ffa28d37 100644 --- a/test/regression/1382-column-highlighter-broken-on-horizontal-scroll/script +++ b/test/regression/1382-column-highlighter-broken-on-horizontal-scroll/script @@ -1,2 +1,2 @@ ui_out -ignore 1 -ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "xxxxxxxxxx" }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "x" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "x" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "xxx\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' +ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "xxxxxxxxxx" }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "x" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "x" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "xxx\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "underline": "default", "attributes": [] }, "contents": " " }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' diff --git a/test/regression/4669-eol-highlight-to-column-highlighter/script b/test/regression/4669-eol-highlight-to-column-highlighter/script index 1353e43d..630904c8 100644 --- a/test/regression/4669-eol-highlight-to-column-highlighter/script +++ b/test/regression/4669-eol-highlight-to-column-highlighter/script @@ -1,2 +1,2 @@ ui_out -ignore 1 -ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "white", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "foo\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }], [{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "b" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "ar\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": ["final_fg","final_bg","final_attr"] }, "contents": " " }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' +ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "white", "bg": "blue", "underline": "default", "attributes": [] }, "contents": "foo\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "b" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "ar\u000a" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "red", "underline": "default", "attributes": [] }, "contents": " " }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }'