From bd65719698e303054aa14482ae95c5ab96d7a643 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 17 Jun 2017 11:46:39 +0100 Subject: [PATCH] Correctly handle tabs when show_whitespaces is added Tabs now align to tab stops instead of always spanning 8 spaces when show_whitespaces is added as a highlighter. This fixes issue #1453. A regression test is also provided. --- src/highlighters.cc | 2 +- .../cmd | 1 + .../display | 6 ++++++ .../in | 0 .../rc | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/cmd create mode 100644 test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/display create mode 100644 test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/in create mode 100644 test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/rc diff --git a/src/highlighters.cc b/src/highlighters.cc index 6e5859fd..72154f13 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -941,7 +941,7 @@ void show_whitespaces(const Context& context, HighlightPass, DisplayBuffer& disp if (cp == '\t') { - int column = (int)get_column(buffer, tabstop, it.coord()); + int column = (int)get_column(buffer, tabstop, (it - 1).coord()); int count = tabstop - (column % tabstop); atom_it->replace(tab + String(tabpad[(CharCount)0], CharCount{count-1})); } diff --git a/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/cmd b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/cmd new file mode 100644 index 00000000..e90acefa --- /dev/null +++ b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/cmd @@ -0,0 +1 @@ +ithisisatest diff --git a/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/display b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/display new file mode 100644 index 00000000..731639e4 --- /dev/null +++ b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/display @@ -0,0 +1,6 @@ +{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "this" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "→ " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "is" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "→ " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "a" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "→ " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "tes" }, { "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "t" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "¬" }]], { "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:14 " }, { "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": " - unnamed0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "attributes": [] }] } +{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 27 }] } +{ "jsonrpc": "2.0", "method": "refresh", "params": [true] } diff --git a/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/in b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/in new file mode 100644 index 00000000..e69de29b diff --git a/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/rc b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/rc new file mode 100644 index 00000000..a0c5ad74 --- /dev/null +++ b/test/regression/1453-show_whitespaces-highlighter-breaks-tab-alignment/rc @@ -0,0 +1 @@ +add-highlighter show_whitespaces