correctly highlight lines with tabs
This commit is contained in:
17
bigtext.py
17
bigtext.py
@@ -11,6 +11,7 @@ from PyQt6.QtGui import *
|
||||
from PyQt6.QtGui import QMouseEvent
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
import constants
|
||||
from ScaledScrollBar import ScaledScrollBar
|
||||
from conversion import humanbytes
|
||||
from highlight import Highlight
|
||||
@@ -283,7 +284,8 @@ class InnerBigText(QWidget):
|
||||
if line_number < len(self.lines):
|
||||
line = self.lines[line_number]
|
||||
column_in_line = self.x_pos_to_column(e.pos().x()) + self._left_offset
|
||||
char_in_line = min(column_in_line, line.length() - 1)
|
||||
column_in_line = min(column_in_line, line.length() - 1) # 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))
|
||||
byte_in_line = line.char_index_to_byte(char_in_line)
|
||||
current_byte = line.byte_offset() + byte_in_line
|
||||
@@ -347,17 +349,19 @@ class InnerBigText(QWidget):
|
||||
# print("paintEvent")
|
||||
painter = QPainter(self)
|
||||
# painter.setFont(self.model.settings.font())
|
||||
#print("%s" % QFontDatabase.families())
|
||||
# print("%s" % QFontDatabase.families())
|
||||
# Courier New, DejaVu Sans Mono
|
||||
painter.setFont(QFont("Courier New", self.model.settings.getint_session('general', "font_size")))
|
||||
painter.setPen(QColor(0, 0, 0))
|
||||
self.update_font_metrics(painter)
|
||||
|
||||
tab_string = " " * constants.tab_width
|
||||
|
||||
lines_to_show = self.lines_shown()
|
||||
# print("%s / %s = %s" %(self.height(), float(self.char_height), lines_to_show))
|
||||
|
||||
self.lines = self.model.data(self._byte_offset, self.scroll_lines, lines_to_show)
|
||||
#print("lines_to_show: %d returned: %d" % (lines_to_show, len(self.lines)))
|
||||
# print("lines_to_show: %d returned: %d" % (lines_to_show, len(self.lines)))
|
||||
self.scroll_lines = 0
|
||||
self._byte_offset = self.lines[0].byte_offset() if len(self.lines) > 0 else 0
|
||||
# print("new byte offset: ", self._byte_offset)
|
||||
@@ -389,7 +393,8 @@ class InnerBigText(QWidget):
|
||||
left_offset = int(-1 * self._left_offset * self.char_width)
|
||||
y_line_offset = self.char_height;
|
||||
for l in self.lines:
|
||||
painter.drawText(left_offset, y_line_offset, l.line())
|
||||
text = l.line().replace("\t", tab_string)
|
||||
painter.drawText(left_offset, y_line_offset, text)
|
||||
y_line_offset = y_line_offset + self.char_height
|
||||
|
||||
painter.end()
|
||||
@@ -406,13 +411,13 @@ class InnerBigText(QWidget):
|
||||
self.highlight_background(painter, rect, highlight.get_brush_full_line())
|
||||
|
||||
for highlight in highlights:
|
||||
left_offset = -1 * self._left_offset * self.char_width
|
||||
left_offset = self._left_offset * self.char_width
|
||||
x1 = highlight.get_start() * self.char_width
|
||||
width = highlight.get_width() * self.char_width
|
||||
y1 = y_line_offset - self.char_height + self.char_height / 7
|
||||
height = self.char_height
|
||||
|
||||
rect = QRect(round(left_offset + x1), round(y1), round(width), round(height))
|
||||
rect = QRect(round(x1 - left_offset), round(y1), round(width), round(height))
|
||||
self.highlight_background(painter, rect, highlight.get_brush())
|
||||
|
||||
def highlight_background(self, painter: QPainter, rect: QRect, brush: QBrush):
|
||||
|
||||
Reference in New Issue
Block a user