Simplify column highlighter and make it more robust

Fixes #1382
This commit is contained in:
Maxime Coste 2017-06-09 15:23:36 +01:00
parent 3612eb50e5
commit 7b9d8d39b1
6 changed files with 20 additions and 38 deletions

View File

@ -647,54 +647,20 @@ HighlighterAndId create_column_highlighter(HighlighterParameters params)
} }
if (not found) if (not found)
{ {
ColumnCount first_buffer_col = -1; ColumnCount last_buffer_col = context.window().position().column;
ColumnCount first_display_col = 0;
for (auto& atom : line) for (auto& atom : line)
{ {
if (atom.has_buffer_range()) if (atom.has_buffer_range() and atom.begin() != atom.end())
{ last_buffer_col = get_column(buffer, tabstop, atom.end());
first_buffer_col = get_column(buffer, tabstop, atom.begin());
break;
}
first_display_col += atom.length();
} }
if (first_buffer_col == -1) ColumnCount count = column - last_buffer_col;
continue;
ColumnCount eol_col = line.length();
ColumnCount count = column + first_display_col - first_buffer_col - eol_col;
if (count >= 0) if (count >= 0)
{ {
if (count > 0) if (count > 0)
line.push_back({String{' ', count}}); line.push_back({String{' ', count}});
line.push_back({String{" "}, face}); line.push_back({String{" "}, face});
} }
else
{
for (auto atom_it = line.end(); atom_it != line.begin() and count < 0; --atom_it)
{
DisplayAtom& atom = *(atom_it-1);
const ColumnCount len = atom.length();
if (atom.type() == DisplayAtom::Text and -count <= len)
{
auto it = atom_it - 1;
ColumnCount pos = len + count;
if (pos > 0)
{
it = ++line.split(it, pos);
pos = 0;
}
if (pos+1 != it->length())
it = line.split(it, pos+1);
apply_face(face)(*it);
break;
}
count += len;
}
}
} }
} }
}; };

View File

@ -0,0 +1,4 @@
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx
xxxx xxxx

View File

@ -0,0 +1,6 @@
{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "xxxxxxxxxx" }, { "face": { "fg": "default", "bg": "blue", "attributes": [] }, "contents": "x" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "x" }], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "xxx\u000a" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "attributes": [] }, "contents": " " }], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "blue", "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:89 " }, { "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": 79 }] }
{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }

View File

@ -0,0 +1,4 @@
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxx xxxx
xxxxxxxx

View File

@ -0,0 +1 @@
add-highlighter column 20 default,blue