fix highlighting for selections

This commit is contained in:
2021-12-03 09:03:34 +01:00
parent 6bacfc065b
commit 5b7ebb2f9b
4 changed files with 10 additions and 13 deletions

View File

@@ -1,9 +1,7 @@
import math import math
import os import os
import re
import time import time
from typing import Optional, List, Callable from typing import Callable
import PyQt6.QtGui
from PyQt6 import QtGui from PyQt6 import QtGui
from PyQt6.QtCore import * from PyQt6.QtCore import *
@@ -14,20 +12,17 @@ from PyQt6.QtWidgets import *
import constants import constants
from ScaledScrollBar import ScaledScrollBar from ScaledScrollBar import ScaledScrollBar
from conversion import humanbytes from conversion import humanbytes
from highlight import Highlight
from highlight_regex import HighlightRegex
from highlight_selection import HighlightSelection from highlight_selection import HighlightSelection
from highlighted_range import HighlightedRange from highlighted_range import HighlightedRange
from highlightingdialog import HighlightingDialog from highlightingdialog import HighlightingDialog
from line import Line
from logFileModel import LogFileModel from logFileModel import LogFileModel
import re
from ravenui import RavenUI from ravenui import RavenUI
from settings import Settings from settings import Settings
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
import threading
class FileObserver(FileSystemEventHandler): class FileObserver(FileSystemEventHandler):
@@ -310,12 +305,12 @@ class InnerBigText(QWidget):
column_in_line = self.x_pos_to_column(e.pos().x()) + self._left_offset column_in_line = self.x_pos_to_column(e.pos().x()) + self._left_offset
column_in_line = min(column_in_line, line.length()) # x was behind the last column of this line column_in_line = min(column_in_line, line.length()) # x was behind the last column of this line
char_in_line = line.column_to_char(column_in_line) char_in_line = line.column_to_char(column_in_line)
# print("%s in line %s" % (char_in_line, line_number)) # print("%s in line %s lcolumn_in_line=%s" % (char_in_line, line_number, column_in_line))
byte_in_line = line.char_index_to_byte(char_in_line) byte_in_line = line.char_index_to_byte(char_in_line)
current_byte = line.byte_offset() + byte_in_line - 1 current_byte = line.byte_offset() + byte_in_line
# print("%s + %s = %s" % (line.byte_offset(), char_in_line, current_byte)) # print("%s + %s = %s" % (line.byte_offset(), char_in_line, current_byte))
else: else:
current_byte = self.model.byte_count() - 1 current_byte = self.model.byte_count()
return current_byte return current_byte
def _has_selection(self): def _has_selection(self):

View File

@@ -1,3 +1,4 @@
01234
01234567890123456789 01234567890123456789
012345678901234567890123456789012345678901234567890123456789 012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789 0123456789012345678901234567890123456789

View File

@@ -5,7 +5,6 @@ from highlighted_range import HighlightedRange
from line import Line from line import Line
from PyQt6.QtCore import * from PyQt6.QtCore import *
from PyQt6.QtGui import * from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from settings import Settings from settings import Settings

View File

@@ -87,6 +87,7 @@ class LogFileModel:
offset_in_line = byte_offset - line.byte_offset() offset_in_line = byte_offset - line.byte_offset()
char_index = line.byte_index_to_char_index(offset_in_line) char_index = line.byte_index_to_char_index(offset_in_line)
current_char = line.line()[char_index] current_char = line.line()[char_index]
# print("read_word: char_index=%s, current_char=%s, line=%s" %(char_index, current_char, line.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())
@@ -123,7 +124,8 @@ class LogFileModel:
while l := f.readline(): while l := f.readline():
new_offset = f.tell() new_offset = f.tell()
line = Line(offset, new_offset, line = Line(offset, new_offset,
l.decode("utf8", errors="ignore").replace("\r", "").replace("\n", "")) l.decode("utf8", errors="ignore") # .replace("\r", "").replace("\n", "")
)
# print("%s %s %s" %(line.byte_offset(), line.line(), line.byte_end())) # print("%s %s %s" %(line.byte_offset(), line.line(), line.byte_end()))
if line.byte_end() <= byte_offset: # line.byte_end() returns the end byte +1 if line.byte_end() <= byte_offset: # line.byte_end() returns the end byte +1
lines_before_offset.append(line) lines_before_offset.append(line)