Do not generate more lines to display than window size

The wrap highlighter was pulling all lines until the cursor, regardless
of whether the cursor was going to be made visible, this could lead to
a display buffer containing much more lines than the actual viewport
which eventually could lead to menu being anchored out of view that
was leading to past-the-end buffer accesses.

Fix the wrap higlighter not to pull lines up to the cursor when it
is not tasked with making the cursor visible, and always trim the
eventual extra lines after highlighting.

Fixes #5118
This commit is contained in:
Maxime Coste 2024-03-22 21:44:37 +11:00
parent a1e6799aa9
commit d5f7cbad87
6 changed files with 40 additions and 1 deletions

View File

@ -719,7 +719,7 @@ struct WrapHighlighter : Highlighter
const ColumnCount marker_len = zero_if_greater(m_marker.column_length(), wrap_column); const ColumnCount marker_len = zero_if_greater(m_marker.column_length(), wrap_column);
for (auto buf_line = setup.first_line, win_line = 0_line; for (auto buf_line = setup.first_line, win_line = 0_line;
win_line < win_height or buf_line <= cursor.line; win_line < win_height or (setup.ensure_cursor_visible and buf_line <= cursor.line);
++buf_line, ++setup.line_count) ++buf_line, ++setup.line_count)
{ {
if (buf_line >= buffer.line_count()) if (buf_line >= buffer.line_count())

View File

@ -148,6 +148,8 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
for (auto& line : m_display_buffer.lines()) for (auto& line : m_display_buffer.lines())
line.trim_from(setup.widget_columns, setup.first_column, m_dimensions.column); line.trim_from(setup.widget_columns, setup.first_column, m_dimensions.column);
if (m_display_buffer.lines().size() > m_dimensions.line)
m_display_buffer.lines().resize((size_t)m_dimensions.line);
m_builtin_highlighters.highlight({context, setup, HighlightPass::Colorize, {}}, m_display_buffer, range); m_builtin_highlighters.highlight({context, setup, HighlightPass::Colorize, {}}, m_display_buffer, range);

View File

@ -0,0 +1,29 @@
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
%(29)

View File

@ -0,0 +1 @@
add-highlighter window/ wrap

View File

@ -0,0 +1,6 @@
ui_out -ignore 6
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "a<space>2<c-x><c-w>" ] }'
ui_out -until-grep menu_show >/dev/null
ui_out -ignore 5
ui_in '{ "jsonrpc": "2.0", "method": "scroll", "params": [ -5 ] }'
ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "2\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "3\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "4\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "5\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "6\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "7\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "8\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "9\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "10\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "11\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "12\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "13\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "14\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "15\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "16\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "17\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "18\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "19\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "20\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "21\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "22\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "23\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "24\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }'