From d37a9fd48a6ced9e13578d7a5456412dae77f5f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 09:35:56 +0000 Subject: [PATCH] Fix marker highlighting for CJK/wide chars not at position 0 Fixes #9705 Fixes #9706 --- kitty/line.c | 2 +- kitty_tests/screen.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/kitty/line.c b/kitty/line.c index c81f10a3e..fd2212342 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -984,7 +984,7 @@ apply_mark(Line *line, const uint16_t mark, index_type *cell_pos, unsigned int * } } else if (line->cpu_cells[x].is_multicell) { *match_pos += lc.count - 1; - index_type x_limit = MIN(line->xnum, mcd_x_limit(line->cpu_cells + x)); + index_type x_limit = MIN(line->xnum, x + mcd_x_limit(line->cpu_cells + x)); for (; x < x_limit; x++) { MARK; } x--; } else { diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 556268057..cbd029b8b 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -3,7 +3,7 @@ from kitty.config import defaults from kitty.fast_data_types import DECAWM, DECCOLM, DECOM, IRM, VT_PARSER_BUFFER_SIZE, Color, ColorProfile, Cursor -from kitty.marks import marker_from_function, marker_from_regex +from kitty.marks import marker_from_function, marker_from_regex, marker_from_text from kitty.window import pagerhist from . import BaseTest, draw_multicell, parse_bytes @@ -999,6 +999,21 @@ class TestScreen(BaseTest): s.draw('x') s.set_marker(marker_from_function(mark_x)) self.ae(s.marked_cells(), [(2, 0, 1), (4, 0, 2)]) + # Test CJK/wide characters not at position 0 (issue #9705) + s = self.create_screen(cols=20) + s.draw('テスト世界') + s.set_marker(marker_from_regex('テ', 3)) + self.ae(s.marked_cells(), cells(0, 1)) + s.set_marker(marker_from_regex('世', 3)) + self.ae(s.marked_cells(), cells(6, 7)) + s.set_marker(marker_from_text('世界', 3)) + self.ae(s.marked_cells(), cells(6, 7, 8, 9)) + s = self.create_screen(cols=20) + s.draw('ABテCD世EF') + s.set_marker(marker_from_regex('テ', 3)) + self.ae(s.marked_cells(), cells(2, 3)) + s.set_marker(marker_from_regex('世', 3)) + self.ae(s.marked_cells(), cells(6, 7)) def test_hyperlinks(self): s = self.create_screen()