only draw visible text

This commit is contained in:
2022-12-18 19:23:14 +01:00
parent 47334e7f07
commit ef7694fdc6

View File

@@ -131,7 +131,7 @@ class BigText(QWidget):
# noinspection PyArgumentList,PyTypeChecker # noinspection PyArgumentList,PyTypeChecker
class InnerBigText(QWidget): class InnerBigText(QWidget):
_byte_offset = 0 _byte_offset = 0
_left_offset = 0 _left_offset = 0 # number of characters the horizontal scrollbar was moved to the right
scroll_lines = 0 scroll_lines = 0
longest_line = 0 longest_line = 0
@@ -504,12 +504,17 @@ class InnerBigText(QWidget):
y_line_offset = self.char_height y_line_offset = self.char_height
for line in self.lines: for line in self.lines:
text = line.line_prepared_for_display() text = line.line_prepared_for_display()
painter.drawText(left_offset, y_line_offset, text) leftmost_visible_char_index = line.column_to_char(self._left_offset - 1)
rightmost_visible_char_index = line.column_to_char(self._left_offset + math.ceil(self.columns_shown()))
text = text[
leftmost_visible_char_index:rightmost_visible_char_index] # reduce string to the visible section before drawing
painter.drawText(0, y_line_offset, text)
# painter.drawText(left_offset, y_line_offset, text)
y_line_offset = y_line_offset + self.char_height y_line_offset = y_line_offset + self.char_height
painter.end() painter.end()
end_ns = time.process_time_ns() end_ns = time.process_time_ns()
#print(f"paint took {(end_ns - start_ns) / 1000000.0}") print(f"paint took {(end_ns - start_ns) / 1000000.0}")
def draw_highlights(self, highlights: [HighlightedRange], painter: QPainter, y_line_offset: int): def draw_highlights(self, highlights: [HighlightedRange], painter: QPainter, y_line_offset: int):