From 5b7ebb2f9bd5f1f2fecf4a359d81c19d8e06ac3c Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 3 Dec 2021 09:03:34 +0100 Subject: [PATCH] fix highlighting for selections --- bigtext.py | 17 ++++++----------- example.log | 1 + highlight_selection.py | 1 - logFileModel.py | 4 +++- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/bigtext.py b/bigtext.py index cfb61db..e324c5a 100644 --- a/bigtext.py +++ b/bigtext.py @@ -1,9 +1,7 @@ import math import os -import re import time -from typing import Optional, List, Callable -import PyQt6.QtGui +from typing import Callable from PyQt6 import QtGui from PyQt6.QtCore import * @@ -14,20 +12,17 @@ from PyQt6.QtWidgets import * import constants from ScaledScrollBar import ScaledScrollBar from conversion import humanbytes -from highlight import Highlight -from highlight_regex import HighlightRegex from highlight_selection import HighlightSelection from highlighted_range import HighlightedRange from highlightingdialog import HighlightingDialog -from line import Line from logFileModel import LogFileModel -import re + from ravenui import RavenUI from settings import Settings from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler -import threading + 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 = 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) - # 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) - 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)) else: - current_byte = self.model.byte_count() - 1 + current_byte = self.model.byte_count() return current_byte def _has_selection(self): diff --git a/example.log b/example.log index 4a97393..577e5a5 100644 --- a/example.log +++ b/example.log @@ -1,3 +1,4 @@ +01234 01234567890123456789 012345678901234567890123456789012345678901234567890123456789 0123456789012345678901234567890123456789 diff --git a/highlight_selection.py b/highlight_selection.py index 3ba2f44..cd4b5c4 100644 --- a/highlight_selection.py +++ b/highlight_selection.py @@ -5,7 +5,6 @@ from highlighted_range import HighlightedRange from line import Line from PyQt6.QtCore import * from PyQt6.QtGui import * -from PyQt6.QtWidgets import * from settings import Settings diff --git a/logFileModel.py b/logFileModel.py index 76a2fe5..1c0d739 100644 --- a/logFileModel.py +++ b/logFileModel.py @@ -87,6 +87,7 @@ class LogFileModel: offset_in_line = byte_offset - line.byte_offset() char_index = line.byte_index_to_char_index(offset_in_line) 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): return current_char, byte_offset, byte_offset + 1 start_in_line = line.byte_index_to_char_index(byte_offset - line.byte_offset()) @@ -123,7 +124,8 @@ class LogFileModel: while l := f.readline(): new_offset = f.tell() 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())) if line.byte_end() <= byte_offset: # line.byte_end() returns the end byte +1 lines_before_offset.append(line)