From b9ca3ee6dcca94b597e9ce4bfc505f0a7f4d6bfe Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 14 Nov 2018 17:47:11 +1100 Subject: [PATCH] Fix column highlighter adding display atoms past the window width --- src/highlighters.cc | 25 ++++++++++--------- .../2562-column-highlighter-bleeding/cmd | 0 .../2562-column-highlighter-bleeding/in | 1 + .../2562-column-highlighter-bleeding/rc | 1 + .../2562-column-highlighter-bleeding/ui-out | 7 ++++++ 5 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 test/regression/2562-column-highlighter-bleeding/cmd create mode 100644 test/regression/2562-column-highlighter-bleeding/in create mode 100644 test/regression/2562-column-highlighter-bleeding/rc create mode 100644 test/regression/2562-column-highlighter-bleeding/ui-out diff --git a/src/highlighters.cc b/src/highlighters.cc index dbc7e8eb..1f8dbfa9 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -595,36 +595,37 @@ std::unique_ptr create_column_highlighter(HighlighterParameters par if (column < 0) return; - auto face = context.context.faces()[facespec]; - auto win_column = context.setup.window_pos.column; + const auto face = context.context.faces()[facespec]; + const auto win_column = context.setup.window_pos.column; + const auto target_col = column - win_column; + if (target_col < 0 or target_col >= context.setup.window_range.column) + return; + for (auto& line : display_buffer.lines()) { - auto target_col = column - win_column; - if (target_col < 0) - return; - + auto remaining_col = target_col; bool found = false; auto first_buf = find_if(line, [](auto& atom) { return atom.has_buffer_range(); }); for (auto atom_it = first_buf; atom_it != line.end(); ++atom_it) { const auto atom_len = atom_it->length(); - if (target_col < atom_len) + if (remaining_col < atom_len) { - if (target_col > 0) - atom_it = ++line.split(atom_it, target_col); + if (remaining_col > 0) + atom_it = ++line.split(atom_it, remaining_col); if (atom_it->length() > 1) atom_it = line.split(atom_it, 1_col); atom_it->face = merge_faces(atom_it->face, face); found = true; break; } - target_col -= atom_len; + remaining_col -= atom_len; } if (found) continue; - if (target_col > 0) - line.push_back({String{' ', target_col}, {}}); + if (remaining_col > 0) + line.push_back({String{' ', remaining_col}, {}}); line.push_back({" ", face}); } }; diff --git a/test/regression/2562-column-highlighter-bleeding/cmd b/test/regression/2562-column-highlighter-bleeding/cmd new file mode 100644 index 00000000..e69de29b diff --git a/test/regression/2562-column-highlighter-bleeding/in b/test/regression/2562-column-highlighter-bleeding/in new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/2562-column-highlighter-bleeding/in @@ -0,0 +1 @@ + diff --git a/test/regression/2562-column-highlighter-bleeding/rc b/test/regression/2562-column-highlighter-bleeding/rc new file mode 100644 index 00000000..c4a3577e --- /dev/null +++ b/test/regression/2562-column-highlighter-bleeding/rc @@ -0,0 +1 @@ +add-highlighter window/ column 81 default,red diff --git a/test/regression/2562-column-highlighter-bleeding/ui-out b/test/regression/2562-column-highlighter-bleeding/ui-out new file mode 100644 index 00000000..d64ac218 --- /dev/null +++ b/test/regression/2562-column-highlighter-bleeding/ui-out @@ -0,0 +1,7 @@ +{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] } +{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "cyan", "attributes": [] }, "contents": "\u000a" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] } +{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] } +{ "jsonrpc": "2.0", "method": "info_hide", "params": [] } +{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "out 1:1 " }, { "face": { "fg": "black", "bg": "yellow", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "attributes": [] }] } +{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 0 }] } +{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }