mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-21 15:44:44 +00:00
Fix erase in line and display orphaning halves of multicell characters
This commit is contained in:
parent
a1dc62a710
commit
e1250cf8fb
2 changed files with 72 additions and 5 deletions
|
|
@ -2871,7 +2871,7 @@ screen_erase_in_line(Screen *self, unsigned int how, bool private) {
|
|||
default: break;
|
||||
}
|
||||
if (n > 0) {
|
||||
nuke_multicell_char_intersecting_with(self, s, n, self->cursor->y, self->cursor->y + 1, false);
|
||||
nuke_multicell_char_intersecting_with(self, s, s + n, self->cursor->y, self->cursor->y + 1, false);
|
||||
screen_dirty_line_graphics(self, self->cursor->y, self->cursor->y, self->linebuf == self->main_linebuf);
|
||||
linebuf_init_line(self->linebuf, self->cursor->y);
|
||||
if (private) {
|
||||
|
|
@ -2932,6 +2932,22 @@ screen_move_into_scrollback(Screen *self) {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nuke_multiline_chars_split_by_erase(Screen *self, unsigned int how, index_type a, index_type b) {
|
||||
// remove chars crossing the erase boundary
|
||||
for (int top = 1; top >= 0; top--) {
|
||||
if (top ? how == 3 : how != 1) continue;
|
||||
CPUCell *cp;
|
||||
GPUCell *gp;
|
||||
index_type y = top ? a : b - 1;
|
||||
linebuf_init_cells(self->linebuf, y, &cp, &gp);
|
||||
for (index_type x = 0; x < self->columns; x++) {
|
||||
if (!cp[x].is_multicell) continue;
|
||||
if (top ? cp[x].y > 0 : cp[x].y + 1 < cp[x].scale) nuke_multicell_char_at(self, x, y, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
screen_erase_in_display(Screen *self, unsigned int how, bool private) {
|
||||
/* Erases display in a specific way.
|
||||
|
|
@ -2950,7 +2966,6 @@ screen_erase_in_display(Screen *self, unsigned int how, bool private) {
|
|||
:param bool private: when ``True`` character attributes are left unchanged
|
||||
*/
|
||||
unsigned int a, b;
|
||||
bool nuke_multicell_chars = true;
|
||||
switch (how) {
|
||||
case 0:
|
||||
a = self->cursor->y + 1;
|
||||
|
|
@ -2962,7 +2977,6 @@ screen_erase_in_display(Screen *self, unsigned int how, bool private) {
|
|||
break;
|
||||
case 22:
|
||||
screen_move_into_scrollback(self);
|
||||
nuke_multicell_chars = false; // they have been moved into scrollback and we would get double deletions
|
||||
how = 2;
|
||||
/* fallthrough */
|
||||
case 2:
|
||||
|
|
@ -2974,11 +2988,11 @@ screen_erase_in_display(Screen *self, unsigned int how, bool private) {
|
|||
grman_clear(self->grman, how == 3, self->cell_size);
|
||||
a = 0;
|
||||
b = self->lines;
|
||||
nuke_multicell_chars = false;
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
if (b > a) {
|
||||
if (how < 3) nuke_multiline_chars_split_by_erase(self, how, a, b);
|
||||
if (how != 3) screen_dirty_line_graphics(self, a, b, self->linebuf == self->main_linebuf);
|
||||
if (private) {
|
||||
for (unsigned int i = a; i < b; i++) {
|
||||
|
|
@ -2988,7 +3002,6 @@ screen_erase_in_display(Screen *self, unsigned int how, bool private) {
|
|||
linebuf_clear_attrs_and_dirty(self->linebuf, i);
|
||||
}
|
||||
} else linebuf_clear_lines(self->linebuf, self->cursor, a, b);
|
||||
if (nuke_multicell_chars) nuke_multicell_char_intersecting_with(self, 0, self->columns, a, b, false);
|
||||
self->is_dirty = true;
|
||||
if (selection_intersects_screen_lines(&self->selections, a, b)) clear_selection(&self->selections);
|
||||
if (selection_intersects_screen_lines(&self->url_ranges, a, b)) clear_selection(&self->url_ranges);
|
||||
|
|
|
|||
|
|
@ -463,6 +463,24 @@ def test_multicell(self: TestMulticell) -> None:
|
|||
s.clear_scrollback()
|
||||
assert_line('\0\0\0\0\0\0')
|
||||
|
||||
# Erase in line with cursor in the right half
|
||||
s.reset()
|
||||
s.cursor.x = 4
|
||||
multicell(s, 'b', width=2)
|
||||
s.cursor.x = 5
|
||||
s.erase_in_line(0)
|
||||
for x in range(s.columns):
|
||||
self.assertIsNone(s.cpu_cells(0, x)['mcd'])
|
||||
for cx in (3, 4, 5):
|
||||
s.reset()
|
||||
s.cursor.x = cx - 1
|
||||
multicell(s, 'b', scale=2)
|
||||
s.cursor.x = cx
|
||||
s.erase_in_line(0)
|
||||
for y in (0, 1):
|
||||
for x in range(s.columns):
|
||||
self.assertIsNone(s.cpu_cells(y, x)['mcd'], f'{cx} {y} {x}')
|
||||
|
||||
# Erase in display
|
||||
for x in (1, 2):
|
||||
s.reset(), s.draw('a'), multicell(s, 'b', scale=2), s.draw('c')
|
||||
|
|
@ -483,6 +501,42 @@ def test_multicell(self: TestMulticell) -> None:
|
|||
self.ae(s.historybuf.line(1).as_ansi(), f'a\x1b]{TEXT_SIZE_CODE};s=2;b\x07c')
|
||||
self.ae(s.historybuf.line(0).as_ansi(), ' ')
|
||||
|
||||
# Erase in display splitting a multiline char
|
||||
def no_mcd(*rows):
|
||||
for y in rows:
|
||||
for x in range(s.columns):
|
||||
self.assertIsNone(s.cpu_cells(y, x)['mcd'], f'{y} {x}')
|
||||
|
||||
for private in (False, True):
|
||||
s.reset()
|
||||
s.cursor.x, s.cursor.y = 2, 1
|
||||
multicell(s, 'a', scale=2)
|
||||
s.cursor.x, s.cursor.y = 4, 1
|
||||
s.erase_in_display(0, private)
|
||||
no_mcd(0, 1, 2)
|
||||
s.reset()
|
||||
s.cursor.x, s.cursor.y = 2, 1
|
||||
multicell(s, 'a', scale=2)
|
||||
s.cursor.x, s.cursor.y = 0, 2
|
||||
s.erase_in_display(1, private)
|
||||
no_mcd(0, 1, 2)
|
||||
|
||||
# char split between history and screen
|
||||
for how, y in ((1, 2), (2, 0)):
|
||||
for private in (False, True):
|
||||
s.reset()
|
||||
s.cursor.x, s.cursor.y = 2, s.lines - 2
|
||||
multicell(s, 'a', scale=2)
|
||||
s.cursor.y = s.lines - 1
|
||||
for i in range(s.lines - 1):
|
||||
s.index()
|
||||
self.ae(s.historybuf.count, s.lines - 1)
|
||||
self.assertIsNotNone(s.cpu_cells(0, 2)['mcd'])
|
||||
s.cursor.x, s.cursor.y = 0, y
|
||||
s.erase_in_display(how, private)
|
||||
no_mcd(0)
|
||||
self.assertNotIn(str(TEXT_SIZE_CODE), s.historybuf.line(0).as_ansi())
|
||||
|
||||
# Insert lines
|
||||
s.reset()
|
||||
multicell(s, 'a', scale=2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue