From be95b176bcfaa3767bc9928c435c157c40514ae3 Mon Sep 17 00:00:00 2001 From: kerty Date: Sat, 25 Jan 2025 15:13:41 +0300 Subject: [PATCH] Fix incorrect first line checks in rendering The right prompt was rendered even if scrolled. The command line wasn't rendering on the first line, starting from 0 to the left prompt length. Steps to reproduce: fish -C 'bind ctrl-g \'commandline $(printf %0"$(math $COLUMNS)"d0) $(seq $(math $LINES - 1))\'' # use ctrl-g # observe that only one '0' is rendered --- src/screen.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/screen.rs b/src/screen.rs index f13f56d66..01aac1e7f 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -1149,8 +1149,8 @@ fn s_line(zelf: &Screen, i: usize) -> &Line { // Output all lines. for i in 0..zelf.desired.line_count() { zelf.actual.create_line(i); - - let start_pos = if i == 0 { left_prompt_width } else { 0 }; + let is_first_line = i == 0 && !zelf.scrolled(); + let start_pos = if is_first_line { left_prompt_width } else { 0 }; let mut current_width = 0; let mut has_cleared_line = false; @@ -1209,7 +1209,7 @@ fn s_line(zelf: &Screen, i: usize) -> &Line { // If we're soft wrapped, and if we're going to change the first character of the next // line, don't skip over the last two characters so that we maintain soft-wrapping. skip_remaining = skip_remaining.min(screen_width.unwrap() - 2); - if i == 0 { + if is_first_line { skip_remaining = skip_remaining.max(left_prompt_width); } } @@ -1300,7 +1300,7 @@ fn s_line(zelf: &Screen, i: usize) -> &Line { } // Output any rprompt if this is the first line. - if i == 0 && right_prompt_width > 0 { + if is_first_line && right_prompt_width > 0 { // Move the cursor to the beginning of the line first to be independent of the width. // This helps prevent staircase effects if fish and the terminal disagree. zelf.r#move(0, 0);