fix: fix Terminal zoom inconsistency

This commit is contained in:
2026-06-17 18:18:46 +02:00
parent 94997c2cda
commit a22ac7ceb4
2 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -12,4 +12,4 @@
#pragma once
#define MONTAUK_BUILD_NUMBER 107
#define MONTAUK_BUILD_NUMBER 108
+12 -2
View File
@@ -795,11 +795,21 @@ static inline void terminal_resize(TerminalState* t, int new_cols, int new_rows)
}
}
int new_scrollback = keep - new_rows;
// Anchor the new visible region to the cursor's line. Treating the bottom
// new_rows of kept content as the screen (the naive keep - new_rows) only
// works when the screen is full: with a partly filled screen -- e.g. a
// shell prompt a few lines down with blank rows below it -- it would push
// the real text up into scrollback and drop the view onto the blank region,
// so a zoom appears to scroll down and strands the cursor in empty space.
// Instead pin the cursor to the bottom row when there is enough history
// above it, otherwise keep the content anchored at the top.
int abs_cursor_y = t->scrollback_lines + t->cursor_y - discard;
if (abs_cursor_y < 0) abs_cursor_y = 0;
int new_scrollback = abs_cursor_y - (new_rows - 1);
if (new_scrollback < 0) new_scrollback = 0;
if (new_scrollback > t->max_scrollback) new_scrollback = t->max_scrollback;
// Adjust cursor
int abs_cursor_y = t->scrollback_lines + t->cursor_y - discard;
int new_cursor_y = abs_cursor_y - new_scrollback;
if (new_cursor_y < 0) new_cursor_y = 0;
if (new_cursor_y >= new_rows) new_cursor_y = new_rows - 1;