From 8f0d2915007c30990004e7ba2a9298c0951332d8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 17 Nov 2024 12:37:27 +0530 Subject: [PATCH] Delete chars with multicell tests --- kitty/screen.c | 9 +++--- kitty_tests/multicell.py | 63 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/kitty/screen.c b/kitty/screen.c index ccfec1045..45e52393b 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -721,9 +721,9 @@ nuke_incomplete_single_line_multicell_chars_in_range( for (index_type x = start; x < limit; x++) { if (cpu_cells[x].is_multicell) { MultiCellData mcd = cell_multicell_data(cpu_cells + x, self->text_cache); - index_type last_x = x + mcd.width; - if (last_x > limit) nuke_in_line(cpu_cells, gpu_cells, x, limit, replace_with_spaces ? ' ': 0); - x = last_x + 1; + index_type mcd_x_limit = x + mcd.width - cpu_cells[x].x; + if (cpu_cells[x].x || mcd_x_limit > limit) nuke_in_line(cpu_cells, gpu_cells, x, MIN(mcd_x_limit, limit), replace_with_spaces ? ' ': 0); + x = mcd_x_limit; } } } @@ -2410,14 +2410,13 @@ remove_characters(Screen *self, index_type at, index_type num, index_type y, boo // and x=at + num - 1 are deleted nuke_multiline_char_intersecting_with(self, at, self->columns, y, y + 1, replace_with_spaces); nuke_split_multicell_char_at_left_boundary(self, at, y, replace_with_spaces); - nuke_split_multicell_char_at_right_boundary(self, at + num - 1, y, replace_with_spaces); CPUCell *cp; GPUCell *gp; linebuf_init_cells(self->linebuf, y, &cp, &gp); // left shift for (index_type i = at; i < self->columns - num; i++) { cp[i] = cp[i+num]; gp[i] = gp[i+num]; } - nuke_split_multicell_char_at_right_boundary(self, at + num - 1, y, replace_with_spaces); + nuke_incomplete_single_line_multicell_chars_in_range(self, at, self->columns, y, replace_with_spaces); } void diff --git a/kitty_tests/multicell.py b/kitty_tests/multicell.py index 9a167422c..77f5c8551 100644 --- a/kitty_tests/multicell.py +++ b/kitty_tests/multicell.py @@ -80,8 +80,10 @@ def test_multicell(self: TestMulticell) -> None: y = s.cursor.y self.ae(text, line_text(y)) - # Test basic multicell drawing s = self.create_screen(cols=6, lines=6) + + # Test basic multicell drawing + s.reset() ac(0, 0, is_multicell=False) multicell(s, 'a') ac(0, 0, is_multicell=True, width=1, scale=1, subscale=0, x=0, y=0, text='a', explicitly_set=True, cursor=(1, 0)) @@ -133,7 +135,7 @@ def test_multicell(self: TestMulticell) -> None: ac(x, 4, text=' ') big_a(0, 0), big_a(1, 1), big_a(2, 2), big_a(5, 1) - # Test insert chars with multicell + # Test insert chars with multicell (aka right shift) s.reset() s.draw('a') s.cursor.x = 0 @@ -166,6 +168,7 @@ def test_multicell(self: TestMulticell) -> None: s.cursor.x = 0 s.insert_characters(1) assert_line('\0\0\0\0\0\0') + # multiline s.reset() s.draw('a') multicell(s, 'b', scale=2) @@ -182,3 +185,59 @@ def test_multicell(self: TestMulticell) -> None: assert_line('a_\0\0\0\0') assert_line('__\0\0\0\0', 1) + # Test delete chars with multicell (aka left shift) + s.reset() + multicell(s, 'a', width=2) + s.cursor.x = 0 + s.delete_characters(1) + assert_line('\0\0\0\0\0\0') + s.reset() + multicell(s, 'a', width=2) + s.cursor.x = 1 + s.delete_characters(1) + assert_line('\0\0\0\0\0\0') + s.reset() + s.draw('ab') + multicell(s, 'a', width=2) + s.cursor.x = 0 + s.delete_characters(2) + assert_line('a_\0\0\0\0') + s.reset() + s.draw('a'), multicell(s, 'b', width=2), s.draw('c') + s.cursor.x = 0 + s.delete_characters(1) + assert_line('b_c\0\0\0') + s.reset() + s.draw('a'), multicell(s, 'b', width=2), s.draw('c') + s.cursor.x = 0 + s.delete_characters(1) + assert_line('b_c\0\0\0') + s.reset(), s.draw('a'), multicell(s, 'b', width=2), s.draw('c') + s.cursor.x = 0 + s.delete_characters(2) + assert_line('\0c\0\0\0\0') + s.reset(), s.draw('a'), multicell(s, 'b', width=2), s.draw('c') + s.cursor.x = 1 + s.delete_characters(1) + assert_line('a\0c\0\0\0') + s.reset(), s.draw('a'), multicell(s, 'b', width=2), s.draw('c') + s.cursor.x = 2 + s.delete_characters(1) + assert_line('a\0c\0\0\0') + + # multiline + s.reset() + s.draw('a'), multicell(s, 'b', scale=2), s.draw('c') + assert_line('ab_c\0\0') + assert_line('\0__\0\0\0', 1) + s.cursor.x, s.cursor.y = 0, 0 + s.delete_characters(1) + assert_line('\0\0c\0\0\0') + assert_line('\0\0\0\0\0\0', 1) + s.reset() + multicell(s, 'a', scale=2) + s.cursor.x = 3 + s.delete_characters(1) + assert_line('a_\0\0\0\0') + assert_line('__\0\0\0\0', 1) +