Cleanup previous PR
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

This commit is contained in:
Kovid Goyal 2026-10-08 08:31:32 +05:30
parent 1bf03eabaa
commit fa9f8dac18
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 90 additions and 16 deletions

View file

@ -2309,8 +2309,8 @@ static bool
scroll_filter_func(ImageRef *ref, Image UNUSED *img, const void *data, CellPixelSize cell UNUSED) {
if (ref->is_virtual_ref) return false;
ScrollData *d = (ScrollData *)data;
// A reverse scroll moves screen lines down but leaves the history in place.
if (d->amt > 0 && is_cell_image(ref) && ref->start_row + (int32_t)ref->effective_num_rows <= 0) return false;
// A reverse scroll that does not pull lines back from the history leaves the history in place
if (d->amt > 0 && !d->scroll_history && ref->start_row + (int32_t)ref->effective_num_rows <= 0) return false;
ref->start_row += d->amt;
// A cell image is tied to the placeholders on its line, which are lost when
// the line is scrolled off the bottom, so the ref must not come back on a
@ -2347,9 +2347,10 @@ static bool
scroll_filter_margins_func(ImageRef *ref, Image *img, const void *data, CellPixelSize cell) {
if (ref->is_virtual_ref) return false;
ScrollData *d = (ScrollData *)data;
// A line scrolled out of a region at the top of the screen still enters the history,
// so a cell image whose line is already in the history moves with it.
if (d->add_to_history && is_cell_image(ref) && ref->start_row + (int32_t)ref->effective_num_rows <= (int32_t)d->margin_top) {
// Lines scrolled out of a region at the top of the screen still enter the history and
// lines popped from the history move it down, so a cell image whose line is in the
// history moves with it.
if (d->scroll_history && is_cell_image(ref) && ref->start_row + (int32_t)ref->effective_num_rows <= 0) {
ref->start_row += d->amt;
return ref->start_row + (int32_t)ref->effective_num_rows <= d->limit;
}

View file

@ -180,7 +180,8 @@ typedef struct {
int32_t amt, limit;
index_type margin_top, margin_bottom;
bool has_margins;
bool add_to_history;
// The history scrolls with the screen: lines move into it (amt < 0) or are popped back from it (amt > 0)
bool scroll_history;
} ScrollData;

View file

@ -433,7 +433,7 @@ index_selection(const Screen *self, Selections *selections, bool up, index_type
bool is_main = self->linebuf == self->main_linebuf; \
static ScrollData s; \
s.amt = amtv; \
s.add_to_history = histv; \
s.scroll_history = histv; \
s.limit = is_main ? -self->historybuf->ynum : 0; \
s.has_margins = self->margin_top != 0 || self->margin_bottom != self->lines - 1; \
s.margin_top = top; \
@ -443,7 +443,7 @@ index_selection(const Screen *self, Selections *selections, bool up, index_type
}
#define INDEX_DOWN \
#define INDEX_DOWN(scroll_history) \
linebuf_reverse_index(self->linebuf, top, bottom); \
linebuf_clear_line(self->linebuf, top, true); \
if (self->linebuf == self->main_linebuf && self->last_visited_prompt.is_set) { \
@ -451,7 +451,7 @@ index_selection(const Screen *self, Selections *selections, bool up, index_type
else if (self->last_visited_prompt.y < self->lines - 1) self->last_visited_prompt.y++; \
else self->last_visited_prompt.is_set = false; \
} \
INDEX_GRAPHICS(1, false) \
INDEX_GRAPHICS(1, scroll_history) \
self->is_dirty = true; \
if (UNLIKELY(self->selections.count)) index_selection(self, &self->selections, false, top, bottom); \
if (UNLIKELY(self->url_ranges.count || self->url_ranges.in_progress)) clear_selection(&self->url_ranges);
@ -724,7 +724,7 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) {
Savepoint *sp = is_main ? &self->main_savepoint : &self->alt_savepoint;
while (self->cursor->y + 1 < self->lines && self->lines - self->cursor->y > lines_after_cursor_before_resize) {
if (!historybuf_pop_line(self->historybuf, self->alt_linebuf->line)) break;
INDEX_DOWN;
INDEX_DOWN(true);
linebuf_copy_line_to(self->main_linebuf, self->alt_linebuf->line, 0);
self->cursor->y++;
sp->cursor.y = MIN(sp->cursor.y + 1, self->lines - 1);
@ -2551,7 +2551,7 @@ screen_reverse_index(Screen *self) {
// Move cursor up one line, scrolling screen if needed
unsigned int top = self->margin_top, bottom = self->margin_bottom;
if (self->cursor->y == top) {
INDEX_DOWN;
INDEX_DOWN(false);
} else screen_cursor_up(self, 1, false, -1);
}
@ -2567,7 +2567,7 @@ _reverse_scroll(Screen *self, unsigned int count, bool fill_from_scrollback) {
while (count-- > 0) {
bool copied = false;
if (fill_from_scrollback) copied = historybuf_pop_line(self->historybuf, self->alt_linebuf->line);
INDEX_DOWN;
INDEX_DOWN(copied);
if (copied) linebuf_copy_line_to(self->main_linebuf, self->alt_linebuf->line, 0);
}
}

View file

@ -1256,14 +1256,86 @@ class TestGraphics(BaseTest):
s.reset()
draw_placeholders()
index_lines(s.lines, 5)
before = scroll_view(6, True)
self.ae(len(before), 2)
def ref_rows(refs):
return sorted(round((1 - r['dest_rect']['top']) / dy) - s.scrolled_by for r in refs)
before = ref_rows(scroll_view(6, True))
self.ae(before, [-3, -2])
scroll_view(6, False)
s.cursor_position(1, 1)
s.reverse_index()
s.update_only_line_graphics_data()
after = scroll_view(6, True)
self.ae(len(after), len(before))
self.ae(ref_rows(scroll_view(6, True)), before)
def test_unicode_placeholders_history_fill(self):
# Lines popped back from the history (CSI + T, or enlarging the window with
# scrollback_fill_enlarged_window) move the history down, so cell images
# rendered for lines in the history must move with them.
cw, ch = 5, 10
s, dx, dy, put_image, put_ref, layers, rect_eq = put_helpers(self, cw, ch, lines=6)
put_image(s, 5, 10, num_cols=1, num_lines=1, unicode_placeholder=1, id=42)
def ref_rows(scrolled_by=0):
s.update_only_line_graphics_data()
return sorted(round((1 - r['dest_rect']['top']) / dy) - scrolled_by for r in layers(s, scrolled_by))
def rows_in_history():
# Render the history lines as when the view is scrolled back
n = s.historybuf.count
s.scroll(n, True)
ans = [r for r in ref_rows(n) if r < 0]
s.scroll(n, False)
s.update_only_line_graphics_data()
return ans
def setup(region):
# Push 'plain' and then a placeholder line into the history
s.reset()
if region:
s.set_margins(1, s.lines - 1)
s.draw('plain')
s.carriage_return(), s.linefeed()
s.apply_sgr('38;5;42')
s.draw('\U0010eeee\u0305')
s.apply_sgr('39')
s.cursor_position(s.lines - 1 if region else s.lines, 1)
s.index(), s.index()
self.ae(str(s.historybuf.line(0)), '\U0010eeee\u0305')
self.ae(rows_in_history(), [-1])
for region in (False, True):
setup(region)
s.reverse_scroll(1, True)
self.ae(str(s.line(0)), '\U0010eeee\u0305')
self.ae(rows_in_history(), [], f'region={region}')
self.ae(ref_rows(), [0], f'region={region}')
def classic_in_history():
nonlocal s, dy, layers
s, _, dy, put_image, _, layers, _ = put_helpers(self, cw, ch, lines=6)
put_image(s, cw, ch) # a one cell image at (0, 0)
s.draw('img')
s.cursor_position(s.lines, 1)
s.index()
self.ae(ref_rows(1), [-1])
# A reverse index that does not pull lines from the history leaves classic
# placements in the history in place
classic_in_history()
s.cursor_position(1, 1)
s.reverse_index()
self.ae(ref_rows(), [])
self.ae(ref_rows(1), [-1])
# Enlarging the window pulls lines back from the history (cell images are
# removed on resize, so only classic placements are left to move)
classic_in_history()
self.set_options({'scrollback_fill_enlarged_window': True})
s.cursor_position(2, 1)
s.resize(s.lines + 1, s.columns)
self.ae(str(s.line(0)), ' img')
self.ae(ref_rows(), [0])
def test_gr_scroll(self):
cw, ch = 10, 20