Fix column highlighter adding display atoms past the window width

This commit is contained in:
Maxime Coste 2018-11-14 17:47:11 +11:00
parent b96ab67479
commit b9ca3ee6dc
5 changed files with 22 additions and 12 deletions

View File

@ -595,36 +595,37 @@ std::unique_ptr<Highlighter> create_column_highlighter(HighlighterParameters par
if (column < 0)
return;
auto face = context.context.faces()[facespec];
auto win_column = context.setup.window_pos.column;
for (auto& line : display_buffer.lines())
{
auto target_col = column - win_column;
if (target_col < 0)
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 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});
}
};

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
add-highlighter window/ column 81 default,red

View File

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