Fix splitting display line in front of a replaced range

When a replaced buffer range atom was starting exactly at the
location we wanted to split onto the code would split *after*
that atom instead of before.

Fixes #4052
This commit is contained in:
Maxime Coste 2021-02-16 12:32:05 +11:00
parent fa3aa3c1a3
commit 978dfe4bdf
5 changed files with 18 additions and 1 deletions

View File

@ -113,7 +113,10 @@ DisplayLine::iterator DisplayLine::split(iterator it, ColumnCount count)
DisplayLine::iterator DisplayLine::split(BufferCoord pos) DisplayLine::iterator DisplayLine::split(BufferCoord pos)
{ {
auto it = find_if(begin(), end(), [pos](const DisplayAtom& a) { return a.type() == DisplayAtom::Range and a.end() > pos; }); auto it = find_if(begin(), end(), [pos](const DisplayAtom& a) {
return (a.has_buffer_range() && a.begin() >= pos) ||
(a.type() == DisplayAtom::Range and a.end() > pos);
});
if (it == end() or it->begin() >= pos) if (it == end() or it->begin() >= pos)
return it; return it;
return ++split(it, pos); return ++split(it, pos);

View File

@ -0,0 +1,3 @@
fn main() {
let my_str = String::from("abc");
}

View File

@ -0,0 +1,4 @@
declare-option -hidden range-specs test_inlay_hints
add-highlighter window/whitespaces show-whitespaces -tab '' -tabpad '⋅' -spc ' ' -nbsp '⍽'
add-highlighter window/test_inlay_hints replace-ranges test_inlay_hints
set buffer test_inlay_hints %val{timestamp} '2.15+0|{Information}{\}: String'

View File

@ -0,0 +1,7 @@
ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }'
ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "f" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "n" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "main()" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "{" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": "¬" }], [{ "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "let" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "my_str" }, { "face": { "fg": "black", "bg": "yellow", "attributes": [] }, "contents": ": String" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "=" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "String::from(\"abc\");" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": "¬" }], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "}" }, { "face": { "fg": "default", "bg": "default", "attributes": ["final_fg"] }, "contents": "¬" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] }'
ui_out '{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] }'
ui_out '{ "jsonrpc": "2.0", "method": "info_hide", "params": [] }'
ui_out '{ "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": [] }] }'
ui_out '{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 0 }] }'
ui_out '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }'