From 195fe8fd29a1824372ff69e6ef8b8e5be8bc9a07 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 12 Jul 2022 19:41:50 +1000 Subject: [PATCH] Fix past-the-eol column highlighter getting highlighted as buffer range Make the column highlighter faces final, and change final logic to give precedence to the base face when both the base and new face are final. Fixes #4669 --- src/display_buffer.hh | 8 ++++---- src/face.hh | 4 ++-- src/highlighters.cc | 17 ++++++++++++++--- test/highlight/column/multi-columns/script | 9 ++------- .../script | 9 ++------- .../cmd | 1 + .../4669-eol-highlight-to-column-highlighter/in | 2 ++ .../4669-eol-highlight-to-column-highlighter/rc | 1 + .../script | 2 ++ 9 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 test/regression/4669-eol-highlight-to-column-highlighter/cmd create mode 100644 test/regression/4669-eol-highlight-to-column-highlighter/in create mode 100644 test/regression/4669-eol-highlight-to-column-highlighter/rc create mode 100644 test/regression/4669-eol-highlight-to-column-highlighter/script diff --git a/src/display_buffer.hh b/src/display_buffer.hh index 6d739095..af37b18f 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -24,11 +24,11 @@ struct DisplayAtom : public UseMemoryDomain public: enum Type { Range, ReplacedRange, Text }; - DisplayAtom(const Buffer& buffer, BufferCoord begin, BufferCoord end) - : m_type(Range), m_buffer(&buffer), m_range{begin, end} {} + DisplayAtom(const Buffer& buffer, BufferCoord begin, BufferCoord end, Face face = {}) + : face(face), m_type(Range), m_buffer(&buffer), m_range{begin, end} {} - DisplayAtom(const Buffer& buffer, BufferCoord begin, BufferCoord end, String str) - : m_type(ReplacedRange), m_buffer(&buffer), m_range{begin, end}, m_text{std::move(str)} {} + DisplayAtom(const Buffer& buffer, BufferCoord begin, BufferCoord end, String str, Face face = {}) + : face(face), m_type(ReplacedRange), m_buffer(&buffer), m_range{begin, end}, m_text{std::move(str)} {} DisplayAtom(String str, Face face) : face(face), m_type(Text), m_text(std::move(str)) {} diff --git a/src/face.hh b/src/face.hh index ce544116..e1047bcd 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 (face.attributes & final_attr) - return face.*color; if (base.attributes & final_attr) return base.*color; + if (face.attributes & final_attr) + return face.*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 6d370aae..5245b3c6 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -558,6 +558,17 @@ 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 ", @@ -604,7 +615,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}, face }); + it->push_back({ String{' ', remaining}, make_final(face) }); }; return make_highlighter(std::move(func)); @@ -670,8 +681,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}}); - line.push_back({buffer, last_pos, last_pos, " "}).face = face; + 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)}); } }; diff --git a/test/highlight/column/multi-columns/script b/test/highlight/column/multi-columns/script index 785773db..67e93c53 100644 --- a/test/highlight/column/multi-columns/script +++ b/test/highlight/column/multi-columns/script @@ -1,7 +1,2 @@ -ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }' -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": [] }] }' -ui_out '{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] }' -ui_out '{ "jsonrpc": "2.0", "method": "info_hide", "params": [] }' -ui_out '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "out 1:1 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }' -ui_out '{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 3 }] }' -ui_out '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }' +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": [] }] }' 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 3f88b24d..60940766 100644 --- a/test/regression/1382-column-highlighter-broken-on-horizontal-scroll/script +++ b/test/regression/1382-column-highlighter-broken-on-horizontal-scroll/script @@ -1,7 +1,2 @@ -ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }' -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": [] }] }' -ui_out '{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] }' -ui_out '{ "jsonrpc": "2.0", "method": "info_hide", "params": [] }' -ui_out '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "out 1:89 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }' -ui_out '{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 79 }] }' -ui_out '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }' +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": [] }] }' diff --git a/test/regression/4669-eol-highlight-to-column-highlighter/cmd b/test/regression/4669-eol-highlight-to-column-highlighter/cmd new file mode 100644 index 00000000..c8f145ff --- /dev/null +++ b/test/regression/4669-eol-highlight-to-column-highlighter/cmd @@ -0,0 +1 @@ +J diff --git a/test/regression/4669-eol-highlight-to-column-highlighter/in b/test/regression/4669-eol-highlight-to-column-highlighter/in new file mode 100644 index 00000000..3bd1f0e2 --- /dev/null +++ b/test/regression/4669-eol-highlight-to-column-highlighter/in @@ -0,0 +1,2 @@ +foo +bar diff --git a/test/regression/4669-eol-highlight-to-column-highlighter/rc b/test/regression/4669-eol-highlight-to-column-highlighter/rc new file mode 100644 index 00000000..ce002364 --- /dev/null +++ b/test/regression/4669-eol-highlight-to-column-highlighter/rc @@ -0,0 +1 @@ +add-highlighter window/ column 6 ,red diff --git a/test/regression/4669-eol-highlight-to-column-highlighter/script b/test/regression/4669-eol-highlight-to-column-highlighter/script new file mode 100644 index 00000000..1353e43d --- /dev/null +++ b/test/regression/4669-eol-highlight-to-column-highlighter/script @@ -0,0 +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": [] }] }'