From 7ffc524175915795513871505233682d804a2e45 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 1 Nov 2021 15:37:07 +0100 Subject: [PATCH] fix word selection when clicking into line with multi byte chars --- logFileModel.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/logFileModel.py b/logFileModel.py index bb142b1..5ed6248 100644 --- a/logFileModel.py +++ b/logFileModel.py @@ -88,18 +88,18 @@ class LogFileModel: current_char = line.line()[line.byte_index_to_char_index(offset_in_line)] if not self._is_word_char(current_char): return (current_char, byte_offset, byte_offset + 1) - start_in_line = byte_offset - line.byte_offset() + start_in_line = line.byte_index_to_char_index(byte_offset - line.byte_offset()) while start_in_line - 1 >= 0 and self._is_word_char(line.line()[start_in_line - 1]): start_in_line = start_in_line - 1 - end_in_line = byte_offset - line.byte_offset() + end_in_line = line.byte_index_to_char_index(byte_offset - line.byte_offset()) while end_in_line < len(line.line()) and self._is_word_char(line.line()[end_in_line]): end_in_line = end_in_line + 1 - start_byte = start_in_line + line.byte_offset() - end_byte = end_in_line + line.byte_offset() + start_byte = line.char_index_to_byte(start_in_line) + line.byte_offset() + end_byte = line.char_index_to_byte(end_in_line) + line.byte_offset() return (line.line()[start_in_line:end_in_line], start_byte, end_byte) def _is_word_char(self, char: str) -> bool: - return re.match("\w", char) + return re.match(r"\w", char) is not None def data(self, byte_offset: int, scroll_lines: int, lines: int) -> List[Line]: # print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines))