Fix marker highlighting for CJK/wide chars not at position 0

Fixes #9705
Fixes #9706
This commit is contained in:
copilot-swe-agent[bot] 2026-03-19 09:35:56 +00:00 committed by Kovid Goyal
parent 0051b7b046
commit d37a9fd48a
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 2 deletions

View file

@ -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 {

View file

@ -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()