From c7fdb8dc6b825ed28004054b456df0e5f96757d4 Mon Sep 17 00:00:00 2001 From: kerty Date: Sat, 18 Oct 2025 23:44:28 +0300 Subject: [PATCH] Simplify behavior of ScreenData.cursor Let `y=0` be the first line of the rendered commandline. Then, in final rendering, the final value of the desired cursor was measured from `y=scroll_amount`. This wasn't a problem because ``` if !MIDNIGHT_COMMANDER_HACK.load() { self.r#move(0, 0); } ``` implicitly changed the actual cursor to be measured from `y=0` to `y=scroll_amount`. This happened because the cursor moved to `y=scroll_amount` but had its `y` value set to 0. Since the actual and desired cursors were both measured from the same line, the code was correct, just unintuitive. Change this to always measure cursor position from the start of the rendered commandline. --- src/screen.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/screen.rs b/src/screen.rs index 57dfe2a68..1b2241c67 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -155,7 +155,7 @@ pub struct ScreenData { screen_width: Option, /// Virtual cursor position used for writing to `line_datas`, - /// and also the viewport final cursor position. + /// and also final cursor position from the start of rendered commandline. cursor: Cursor, /// Number of prompt lines rendered on the screen. @@ -494,10 +494,8 @@ struct ScrolledCursor { mut cursor, scroll_amount, } = scrolled_cursor; - if scroll_amount != 0 { - if !is_final_rendering { - self.desired.line_datas = self.desired.line_datas.split_off(scroll_amount); - } + if scroll_amount != 0 && !is_final_rendering { + self.desired.line_datas = self.desired.line_datas.split_off(scroll_amount); cursor.y -= scroll_amount; } cursor @@ -1322,7 +1320,7 @@ fn s_line(zelf: &Screen, i: usize) -> &Line { // Don't do it when running in midnight_commander because of // https://midnight-commander.org/ticket/4258. if !MIDNIGHT_COMMANDER_HACK.load() { - self.r#move(0, 0); + self.r#move(0, self.actual.cursor.y); } // Clear remaining lines (if any) if we haven't cleared the screen.