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.
This commit is contained in:
Tomasz Kramkowski 2017-06-17 11:46:39 +01:00
parent a37ccf4238
commit bd65719698
5 changed files with 9 additions and 1 deletions

View File

@ -941,7 +941,7 @@ void show_whitespaces(const Context& context, HighlightPass, DisplayBuffer& disp
if (cp == '\t') 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); int count = tabstop - (column % tabstop);
atom_it->replace(tab + String(tabpad[(CharCount)0], CharCount{count-1})); atom_it->replace(tab + String(tabpad[(CharCount)0], CharCount{count-1}));
} }

View File

@ -0,0 +1 @@
ithis<tab>is<tab>a<tab>test<esc>

View File

@ -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] }

View File

@ -0,0 +1 @@
add-highlighter show_whitespaces