fix the way tabs are used
The previous code just assumed a tab was 4 spaces wide. This is not true, because a tab can be between 1 and 4 spaces wide.
This commit is contained in:
17
bigtext.py
17
bigtext.py
@@ -3,7 +3,7 @@ import sys
|
||||
import math
|
||||
import os
|
||||
import time
|
||||
from typing import Callable
|
||||
from typing import Callable, List
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from PyQt6.QtCore import *
|
||||
@@ -17,6 +17,7 @@ from conversion import humanbytes
|
||||
from highlight_selection import HighlightSelection
|
||||
from highlighted_range import HighlightedRange
|
||||
from highlightingdialog import HighlightingDialog
|
||||
from line import Line
|
||||
from logFileModel import LogFileModel
|
||||
|
||||
|
||||
@@ -126,7 +127,7 @@ class InnerBigText(QWidget):
|
||||
self.customContextMenuRequested.connect(self._open_menu)
|
||||
|
||||
self.update_font_metrics(QPainter(self))
|
||||
self.lines = []
|
||||
self.lines = List[Line]
|
||||
self.selection_highlight = HighlightSelection()
|
||||
self._last_double_click_time = 0
|
||||
self._last_double_click_line_number = -1
|
||||
@@ -213,7 +214,7 @@ class InnerBigText(QWidget):
|
||||
# triple click: select line
|
||||
line_number = self.y_pos_to_line(e.pos().y())
|
||||
if line_number == self._last_double_click_line_number and line_number < len(self.lines):
|
||||
line = self.lines[line_number]
|
||||
line: Line = self.lines[line_number]
|
||||
self.selection_highlight.set_start(line.byte_offset())
|
||||
self.selection_highlight.set_end_byte(line.byte_end())
|
||||
self.update()
|
||||
@@ -227,7 +228,7 @@ class InnerBigText(QWidget):
|
||||
|
||||
line_number = self.y_pos_to_line(e.pos().y())
|
||||
if line_number < len(self.lines):
|
||||
line = self.lines[line_number]
|
||||
line: Line = self.lines[line_number]
|
||||
for listener in self.line_click_listeners:
|
||||
listener(line.byte_offset())
|
||||
|
||||
@@ -303,11 +304,11 @@ class InnerBigText(QWidget):
|
||||
line_number = self.y_pos_to_line(e.pos().y())
|
||||
|
||||
if line_number < len(self.lines):
|
||||
line = self.lines[line_number]
|
||||
line: Line = self.lines[line_number]
|
||||
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_in_columns()) # x was behind the last column of this line
|
||||
char_in_line = line.column_to_char(column_in_line)
|
||||
# print("%s in line %s lcolumn_in_line=%s" % (char_in_line, line_number, column_in_line))
|
||||
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
|
||||
# print("%s + %s = %s" % (line.byte_offset(), char_in_line, current_byte))
|
||||
@@ -414,7 +415,7 @@ class InnerBigText(QWidget):
|
||||
left_offset = int(-1 * self._left_offset * self.char_width)
|
||||
y_line_offset = self.char_height;
|
||||
for l in self.lines:
|
||||
text = l.line() # .replace("\t", tab_string)
|
||||
text = l.line_tabs_replaced()
|
||||
painter.drawText(left_offset, y_line_offset, text)
|
||||
y_line_offset = y_line_offset + self.char_height
|
||||
|
||||
|
||||
Reference in New Issue
Block a user