From e11e62674f486478d225f3990550dd5dac6df489 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 4 Jan 2025 00:35:28 +0100 Subject: [PATCH] Fix bad layout computation with right prompt Commit 1c4e5cadf2 (Autosuggestions in multi-line command lines, 2024-12-15) accidentally passed an empty "commandline_before_suggestion" to compute_layout() when there is no autosuggestion. Closes #10996 --- src/reader.rs | 7 ++++--- tests/checks/tmux-commandline.fish | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index c6018df28..8716099ce 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1545,7 +1545,7 @@ impl<'a> Reader<'a> { Cow::Owned( wstr::from_char_slice(&[get_obfuscation_read_char()]).repeat(cmd_line.len()), ), - 0..0, + None, ) } else if self.is_at_line_with_autosuggestion() { // Combine the command and autosuggestion into one string. @@ -1559,11 +1559,12 @@ impl<'a> Reader<'a> { autosuggestion.search_string_range.clone(), &autosuggestion.text, )), - autosuggested_start..autosuggested_end, + Some(autosuggested_start..autosuggested_end), ) } else { - (Cow::Borrowed(cmd_line.text()), 0..0) + (Cow::Borrowed(cmd_line.text()), None) }; + let autosuggested_range = autosuggested_range.unwrap_or(full_line.len()..full_line.len()); // Copy the colors and insert the autosuggestion color. let data = &self.data.rendered_layout; diff --git a/tests/checks/tmux-commandline.fish b/tests/checks/tmux-commandline.fish index 74c7e0211..4c1c96fd3 100644 --- a/tests/checks/tmux-commandline.fish +++ b/tests/checks/tmux-commandline.fish @@ -11,7 +11,7 @@ tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 1> echo foobar|cat -isolated-tmux send-keys C-k C-u C-l 'commandline -i (seq $LINES) scroll_here' Enter +isolated-tmux send-keys C-k C-u C-l 'commandline -i "\'$(seq $LINES)" scroll_here' Enter tmux-sleep isolated-tmux capture-pane -p # CHECK: 2 @@ -24,3 +24,19 @@ isolated-tmux capture-pane -p # CHECK: 9 # CHECK: 10 # CHECK: scroll_here + +# Soft-wrapped commandline with omitted right prompt. +isolated-tmux send-keys C-c +tmux-sleep +isolated-tmux send-keys C-l ' + function fish_right_prompt + echo right-prompt + end + commandline -i "echo $(printf %0"$COLUMNS"d)" +' Enter +tmux-sleep +isolated-tmux capture-pane -p | sed 1,5d +# CHECK: prompt 4> echo 00000000000000000000000000000000000000000000000000000000000000000 +# CHECK: 000000000000000 +# CHECK: 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +# CHECK: prompt 5> right-prompt