From 2274b8a912f772e8b25b52471563028ccae19a69 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 25 Mar 2024 19:39:35 -0600 Subject: [PATCH] fix(terminal): don't reset x when indexing in scroll region --- src/terminal/Terminal.zig | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index a541c4e07..43299df45 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1094,6 +1094,15 @@ pub fn index(self: *Terminal) !void { // Otherwise use a fast path function from PageList to efficiently // scroll the contents of the scrolling region. + + // eraseRow and eraseRowBounded will end up moving the cursor pin + // up by 1, so we save its current position and restore it after. + const cursor_x = self.screen.cursor.x; + const cursor_y = self.screen.cursor.y; + defer { + self.screen.cursorAbsolute(cursor_x, cursor_y); + } + if (self.scrolling_region.bottom < self.rows) { try self.screen.pages.eraseRowBounded( .{ .active = .{ .y = self.scrolling_region.top } }, @@ -1116,16 +1125,6 @@ pub fn index(self: *Terminal) !void { self.screen.cursor.style = .{}; self.screen.manualStyleUpdate() catch unreachable; }; - - // We scrolled with the cursor on the bottom row of the scrolling - // region, so we should move the cursor to the bottom left. - self.screen.cursorAbsolute( - self.scrolling_region.left, - self.scrolling_region.bottom, - ); - - // Always unset pending wrap - self.screen.cursor.pending_wrap = false; } return;