From 0cd3ed4b84e4cf02e560f0fd65a49c1633f915cb Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 2 Dec 2021 04:40:55 +0100 Subject: [PATCH] Fix completion pager rendering when there are lines after cursor When the completion pager fills up all lines of the screen, we subtract from the pager size the number of lines occupied by the prompt + command line buffer (typically 1), so the command line is always visible. However, we only subtract the number of lines *before* the cursor, so on some multiline commandlines we draw a pager that is too large for our screen, clobbering the commandline rendering. Fix this by counting all lines. Fixes #8509 Possibly fixes #8405 --- src/screen.cpp | 3 ++- tests/checks/tmux-complete.fish | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/screen.cpp b/src/screen.cpp index abb043859..7ef17100b 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1220,6 +1220,8 @@ void screen_t::write(const wcstring &left_prompt, const wcstring &right_prompt, cursor_arr = this->desired.cursor; } + int full_line_count = this->desired.cursor.y + 1; + // Now that we've output everything, set the cursor to the position that we saved in the loop // above. this->desired.cursor = cursor_arr; @@ -1231,7 +1233,6 @@ void screen_t::write(const wcstring &left_prompt, const wcstring &right_prompt, // Re-render our completions page if necessary. Limit the term size of the pager to the true // term size, minus the number of lines consumed by our string. - int full_line_count = cursor_arr.y + 1; pager.set_term_size(termsize_t{std::max(1, curr_termsize.width), std::max(1, curr_termsize.height - full_line_count)}); pager.update_rendering(&page_rendering); diff --git a/tests/checks/tmux-complete.fish b/tests/checks/tmux-complete.fish index bad378881..2fc607551 100644 --- a/tests/checks/tmux-complete.fish +++ b/tests/checks/tmux-complete.fish @@ -28,3 +28,14 @@ isolated-tmux capture-pane -p # The "bc" part is the autosuggestion - we could use "capture-pane -e" to check colors. # CHECK: prompt 2> foo2 aabc # CHECK: aabc aaBd + +# Check that a larger-than-screen completion list does not stomp a multiline commandline (#8509). +isolated-tmux send-keys C-u 'complete -c foo3 -fa "(seq $LINES)\t(string repeat -n $COLUMNS d)"' Enter \ + C-l begin Enter foo3 Enter "echo some trailing line" \ + C-p C-e Space Tab Tab +tmux-sleep +isolated-tmux capture-pane -p | sed -n '1p;$p' +# Assert that we didn't change the command line. +# CHECK: prompt 3> begin +# Also ensure that the pager is actually fully disclosed. +# CHECK: rows 1 to 6 of 10