fix word selection when clicking into line with multi byte chars
This commit is contained in:
@@ -88,18 +88,18 @@ class LogFileModel:
|
|||||||
current_char = line.line()[line.byte_index_to_char_index(offset_in_line)]
|
current_char = line.line()[line.byte_index_to_char_index(offset_in_line)]
|
||||||
if not self._is_word_char(current_char):
|
if not self._is_word_char(current_char):
|
||||||
return (current_char, byte_offset, byte_offset + 1)
|
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]):
|
while start_in_line - 1 >= 0 and self._is_word_char(line.line()[start_in_line - 1]):
|
||||||
start_in_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]):
|
while end_in_line < len(line.line()) and self._is_word_char(line.line()[end_in_line]):
|
||||||
end_in_line = end_in_line + 1
|
end_in_line = end_in_line + 1
|
||||||
start_byte = start_in_line + line.byte_offset()
|
start_byte = line.char_index_to_byte(start_in_line) + line.byte_offset()
|
||||||
end_byte = end_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)
|
return (line.line()[start_in_line:end_in_line], start_byte, end_byte)
|
||||||
|
|
||||||
def _is_word_char(self, char: str) -> bool:
|
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]:
|
def data(self, byte_offset: int, scroll_lines: int, lines: int) -> List[Line]:
|
||||||
# print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines))
|
# print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines))
|
||||||
|
|||||||
Reference in New Issue
Block a user