mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-17 21:54:03 +00:00
Graphics: move Unicode placeholder cell images with lines scrolled into history from a region
A line scrolled out of a region whose top is row 0 (tmux with a bottom status line) enters the history, but scroll_filter_margins_func left the refs of history lines in place, so they drew over other lines on the next scroll back. A reverse scroll also moved history refs although the history does not move.
This commit is contained in:
parent
e4187643a6
commit
1bf03eabaa
4 changed files with 68 additions and 3 deletions
|
|
@ -2309,6 +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;
|
||||
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
|
||||
|
|
@ -2345,6 +2347,12 @@ 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) {
|
||||
ref->start_row += d->amt;
|
||||
return ref->start_row + (int32_t)ref->effective_num_rows <= d->limit;
|
||||
}
|
||||
if (ref_within_region(ref, d->margin_top, d->margin_bottom)) {
|
||||
ref->start_row += d->amt;
|
||||
if (ref_outside_region(ref, d->margin_top, d->margin_bottom)) return true;
|
||||
|
|
|
|||
|
|
@ -180,6 +180,7 @@ typedef struct {
|
|||
int32_t amt, limit;
|
||||
index_type margin_top, margin_bottom;
|
||||
bool has_margins;
|
||||
bool add_to_history;
|
||||
} ScrollData;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -427,12 +427,13 @@ index_selection(const Screen *self, Selections *selections, bool up, index_type
|
|||
}
|
||||
|
||||
|
||||
#define INDEX_GRAPHICS(amtv) \
|
||||
#define INDEX_GRAPHICS(amtv, histv) \
|
||||
{ \
|
||||
if (UNLIKELY(grman_has_any_images(self->grman))) { \
|
||||
bool is_main = self->linebuf == self->main_linebuf; \
|
||||
static ScrollData s; \
|
||||
s.amt = amtv; \
|
||||
s.add_to_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; \
|
||||
|
|
@ -450,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) \
|
||||
INDEX_GRAPHICS(1, false) \
|
||||
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);
|
||||
|
|
@ -2493,7 +2494,7 @@ screen_cursor_to_column(Screen *self, unsigned int column) {
|
|||
|
||||
#define INDEX_UP(add_to_history) \
|
||||
linebuf_index(self->linebuf, top, bottom); \
|
||||
INDEX_GRAPHICS(-1) \
|
||||
INDEX_GRAPHICS(-1, add_to_history) \
|
||||
if (add_to_history) { \
|
||||
/* Only add to history when no top margin has been set */ \
|
||||
linebuf_init_line(self->linebuf, bottom); \
|
||||
|
|
|
|||
|
|
@ -1210,6 +1210,61 @@ class TestGraphics(BaseTest):
|
|||
s.update_only_line_graphics_data()
|
||||
self.ae(len(layers(s)), 0)
|
||||
|
||||
def test_unicode_placeholders_history_margins(self):
|
||||
# Lines scrolled out of a region at the top of the screen (as tmux does for
|
||||
# a pane above its status line) enter the history, and the cell images
|
||||
# rendered for them while the view was scrolled back 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, 20, num_cols=1, num_lines=2, unicode_placeholder=1, id=42)
|
||||
|
||||
def draw_placeholders():
|
||||
s.apply_sgr('38;5;42')
|
||||
s.cursor_position(3, 1)
|
||||
s.draw('\U0010eeee\u0305')
|
||||
s.cursor_position(4, 1)
|
||||
s.draw('\U0010eeee\u030d')
|
||||
s.apply_sgr('39')
|
||||
|
||||
def index_lines(row, n):
|
||||
s.cursor_position(row, 1)
|
||||
for i in range(n):
|
||||
s.draw('plain')
|
||||
s.index()
|
||||
s.carriage_return()
|
||||
s.update_only_line_graphics_data()
|
||||
|
||||
def scroll_view(amt, up):
|
||||
s.scroll(amt, up)
|
||||
s.update_only_line_graphics_data()
|
||||
return layers(s, s.scrolled_by)
|
||||
|
||||
for region in (True, False):
|
||||
s.reset()
|
||||
if region:
|
||||
s.set_margins(1, s.lines - 1)
|
||||
bottom = s.lines - 1 if region else s.lines
|
||||
draw_placeholders()
|
||||
index_lines(bottom, 8)
|
||||
self.ae(len(scroll_view(6, True)), 2)
|
||||
scroll_view(6, False)
|
||||
index_lines(bottom, 3)
|
||||
self.ae(len(scroll_view(9, True)), 0, f'region={region}')
|
||||
scroll_view(9, False)
|
||||
|
||||
# A reverse index must not move the refs of lines in the history
|
||||
s.reset()
|
||||
draw_placeholders()
|
||||
index_lines(s.lines, 5)
|
||||
before = scroll_view(6, True)
|
||||
self.ae(len(before), 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))
|
||||
|
||||
def test_gr_scroll(self):
|
||||
cw, ch = 10, 20
|
||||
s, dx, dy, put_image, put_ref, layers, rect_eq = put_helpers(self, cw, ch)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue