Fix not preserving empty last line in multiline prompts

Reproduction:
fish -C '
    function fish_prompt
        echo left-prompt\n
    end
    function fish_right_prompt
        echo right-prompt
    end
'
and pressing Enter would not preserve the line with right prompt.

This occurred because Screen::cursor_is_wrapped_to_own_line assumed
the last prompt line always had index 0. However, commit 606802daa (Make
ScreenData track multiline prompt, 2025-10-15) changed this so the last
prompt line's index is now `Screen.actual.visible_prompt_lines - 1`.

Screen::cursor_is_wrapped_to_own_line also didn't account for situations
where commandline indentation was 0.

Fix Screen::cursor_is_wrapped_to_own_line and add tests for prompts with
empty last lines.
This commit is contained in:
kerty
2025-10-19 17:09:00 +03:00
committed by Johannes Altmanninger
parent e7ad7e5cf6
commit 0b7ab5a1b5
2 changed files with 82 additions and 1 deletions

View File

@@ -753,8 +753,9 @@ pub fn save_status(&mut self) {
pub fn cursor_is_wrapped_to_own_line(&self) -> bool {
// Don't consider dumb terminals to have wrapping for the purposes of this function.
self.actual.cursor.x == 0
&& self.actual.cursor.y != 0
&& self.actual.cursor.y + 1 != self.actual.visible_prompt_lines
&& self.actual.cursor.y + 1 == self.actual.line_count()
&& self.actual.line(self.actual.cursor.y - 1).is_soft_wrapped
&& !is_dumb()
}

View File

@@ -0,0 +1,80 @@
#RUN: %fish %s
#REQUIRES: command -v tmux
isolated-tmux-start
isolated-tmux send-keys '
function fish_prompt; end
function fish_right_prompt
set -q right_prompt
and echo right-prompt
end
set right_prompt 1
bind ctrl-g "set right_prompt 1" repaint
bind alt-g "set -e right_prompt" repaint
'
tmux-sleep
isolated-tmux send-keys M-g C-l Enter
tmux-sleep
isolated-tmux send-keys C-g Enter
tmux-sleep
isolated-tmux capture-pane -p | string replace -r '$' '+'
#CHECK: +
#CHECK: right-prompt+
#CHECK: right-prompt+
#CHECK: +
#CHECK: +
#CHECK: +
#CHECK: +
#CHECK: +
#CHECK: +
#CHECK: +
isolated-tmux send-keys M-g Tab Tab
tmux-sleep
isolated-tmux capture-pane -p | string replace -r '$' '+'
#CHECK: +
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
isolated-tmux send-keys '
function fish_prompt
echo left-prompt\n
end
'
tmux-sleep
isolated-tmux send-keys C-l Enter
tmux-sleep
isolated-tmux send-keys C-g Enter
tmux-sleep
isolated-tmux capture-pane -p | string replace -r '$' '+'
#CHECK: left-prompt+
#CHECK: +
#CHECK: left-prompt+
#CHECK: right-prompt+
#CHECK: left-prompt+
#CHECK: right-prompt+
#CHECK: +
#CHECK: +
#CHECK: +
#CHECK: +
isolated-tmux send-keys M-g Tab Tab
tmux-sleep
isolated-tmux capture-pane -p | string replace -r '$' '+'
#CHECK: left-prompt+
#CHECK: +
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+
#CHECK: {{.*}}+