cleanup
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from PyQt6.QtCore import pyqtSignal
|
from PyQt6.QtCore import pyqtSignal
|
||||||
@@ -79,15 +77,15 @@ class LogFileModel:
|
|||||||
def read_word_at(self, byte_offset: int) -> (str, int, int):
|
def read_word_at(self, byte_offset: int) -> (str, int, int):
|
||||||
lines = self.data(byte_offset, 0, 1)
|
lines = self.data(byte_offset, 0, 1)
|
||||||
if len(lines) == 0:
|
if len(lines) == 0:
|
||||||
return ("", -1, -1)
|
return "", -1, -1
|
||||||
line: Line = lines[0]
|
line: Line = lines[0]
|
||||||
if not lines[0].includes_byte(byte_offset):
|
if not lines[0].includes_byte(byte_offset):
|
||||||
return ("", -1, -1)
|
return "", -1, -1
|
||||||
|
|
||||||
offset_in_line = byte_offset - line.byte_offset()
|
offset_in_line = byte_offset - line.byte_offset()
|
||||||
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 = line.byte_index_to_char_index(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
|
||||||
@@ -96,7 +94,7 @@ class LogFileModel:
|
|||||||
end_in_line = end_in_line + 1
|
end_in_line = end_in_line + 1
|
||||||
start_byte = line.char_index_to_byte(start_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()
|
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(r"\w", char) is not None
|
return re.match(r"\w", char) is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user