separate highlight selection from other selections

will make it easier to manage other selections externally
This commit is contained in:
2021-10-25 17:26:00 +02:00
parent 76d4dccf1d
commit b8eb62a3bf
2 changed files with 9 additions and 13 deletions

View File

@@ -43,10 +43,7 @@ class BigText(QWidget):
self.v_scroll_bar.setPageStep(1) self.v_scroll_bar.setPageStep(1)
self.v_scroll_bar.valueChanged.connect(big_text.v_scroll_event) self.v_scroll_bar.valueChanged.connect(big_text.v_scroll_event)
self.grid.addWidget(big_text,0,0) self.grid.addWidget(big_text,0,0)
self.grid.addWidget(self.h_scroll_bar, 1, 0) self.grid.addWidget(self.h_scroll_bar, 1, 0)
self.grid.addWidget(self.v_scroll_bar, 0, 1) self.grid.addWidget(self.v_scroll_bar, 0, 1)
@@ -69,14 +66,13 @@ class InnerBigText(QWidget):
self.font = QFont("monospace", 12) self.font = QFont("monospace", 12)
self.update_font_metrics(QPainter(self)) self.update_font_metrics(QPainter(self))
self.lines = [] self.lines = []
self.selection_highlight = HighlightSelection(0, 0) self.selection_highlight = HighlightSelection()
self.highlights = [ self.highlights = [
HighlightRegex( HighlightRegex(
r"INFO", r"INFO",
brush=QBrush(QColor(220, 112, 122)), brush=QBrush(QColor(220, 112, 122)),
brush_full_line=QBrush(QColor(255, 112, 122)) brush_full_line=QBrush(QColor(255, 112, 122))
), )
self.selection_highlight,
] ]
@@ -207,12 +203,14 @@ class InnerBigText(QWidget):
for l in self.lines: for l in self.lines:
self.update_longest_line(len(l.line())) self.update_longest_line(len(l.line()))
highlighters = self.highlights + [self.selection_highlight]
# draw hightlights first - some characters may overlap to the next line # draw hightlights first - some characters may overlap to the next line
# by drawing the background hightlights first we prevent that the hightlight # by drawing the background hightlights first we prevent that the hightlight
# draws over a character # draws over a character
y_line_offset = self.char_height; y_line_offset = self.char_height;
for l in self.lines: for l in self.lines:
for h in self.highlights: for h in highlighters:
optional_highlight_range = h.compute_highlight(l) optional_highlight_range = h.compute_highlight(l)
if optional_highlight_range: if optional_highlight_range:
for highlight in optional_highlight_range: for highlight in optional_highlight_range:

View File

@@ -11,10 +11,8 @@ from settings import Settings
class HighlightSelection(Highlight): class HighlightSelection(Highlight):
start_byte = 0
def __init__(self, start_byte: int, end_byte: int): end_byte = 0
self.start_byte = start_byte
self.end_byte = end_byte
def set_start(self, start_byte): def set_start(self, start_byte):
self.start_byte = start_byte self.start_byte = start_byte
@@ -33,9 +31,9 @@ class HighlightSelection(Highlight):
start = 0 start = 0
if line.includes_byte(end): if line.includes_byte(end):
length = end - line.byte_offset() - start length = end - line.byte_offset() - start
else: else:
length = Settings.max_line_length() -start length = Settings.max_line_length() - start
return [HighlightedRange(start, length, brush=QBrush(QColor(156, 215, 255)), pen=Qt.PenStyle.NoPen)] return [HighlightedRange(start, length, brush=QBrush(QColor(156, 215, 255)), pen=Qt.PenStyle.NoPen)]
else: else: