compute between bytes and chars to get correct clipboard copy
This commit is contained in:
@@ -168,8 +168,8 @@ class InnerBigText(QWidget):
|
||||
column_in_line = self.x_pos_to_column(e.pos().x()) + self._left_offset
|
||||
char_in_line = min(column_in_line, line.length())
|
||||
# print("%s in line %s" % (char_in_line, line_number))
|
||||
|
||||
current_byte = line.byte_offset() + char_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))
|
||||
else:
|
||||
current_byte = self.model.byte_count()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
|
||||
...............................|
|
||||
|
|
||||
äääääääääääääääääääääääääääääää|
|
||||
ääääääääääääää|ääääääääääääääää|
|
||||
2019-08-07 00:00:10,391 [catalina-exec-40] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1u5]
|
||||
2019-08-07 00:00:16,377 [catalina-exec-56] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1u6]
|
||||
2019-08-07 00:00:40,403 [catalina-exec-26] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1ud]
|
||||
|
||||
@@ -26,15 +26,23 @@ class HighlightSelection(Highlight):
|
||||
|
||||
if line.intersects(begin, end):
|
||||
if line.includes_byte(begin):
|
||||
start = begin - line.byte_offset()
|
||||
start_byte_in_line = begin - line.byte_offset()
|
||||
else:
|
||||
start = 0
|
||||
start_byte_in_line = 0
|
||||
|
||||
if line.includes_byte(end):
|
||||
length = end - line.byte_offset() - start
|
||||
length_in_bytes = end - line.byte_offset() - start_byte_in_line
|
||||
else:
|
||||
length = Settings.max_line_length() - start
|
||||
# renders the highlighting to the end of the line
|
||||
# this is how selections usually behave
|
||||
length_in_bytes = Settings.max_line_length() - start_byte_in_line
|
||||
|
||||
return [HighlightedRange(start, length, brush=QBrush(QColor(156, 215, 255)), pen=Qt.PenStyle.NoPen)]
|
||||
start_char = line.byte_index_to_char_index(start_byte_in_line)
|
||||
end_char = line.byte_index_to_char_index(start_byte_in_line+length_in_bytes)
|
||||
length_in_chars = end_char - start_char
|
||||
|
||||
#print("selected: %s" % (line.substr(start_char, length_in_chars)))
|
||||
|
||||
return [HighlightedRange(start_char, length_in_chars, brush=QBrush(QColor(156, 215, 255)), pen=Qt.PenStyle.NoPen)]
|
||||
else:
|
||||
return None
|
||||
|
||||
16
line.py
16
line.py
@@ -4,18 +4,26 @@ class Line:
|
||||
self._byte_end = byte_end
|
||||
self._line = line
|
||||
|
||||
def byte_offset(self):
|
||||
def byte_offset(self) -> int:
|
||||
return self._byte_offset
|
||||
|
||||
def byte_end(self):
|
||||
def byte_end(self) -> int:
|
||||
return self._byte_end
|
||||
|
||||
def line(self):
|
||||
def line(self) -> str:
|
||||
return self._line
|
||||
|
||||
def length(self):
|
||||
def length(self) -> int:
|
||||
return len(self._line)
|
||||
|
||||
def char_index_to_byte(self, char_in_line: int) -> int:
|
||||
return len(self.prefix(char_in_line).encode("utf8"))
|
||||
|
||||
def byte_index_to_char_index(self, byte_index: int) -> int:
|
||||
prefix_bytes = self._line.encode("utf8")[:byte_index]
|
||||
prefix_chars = prefix_bytes.decode("utf8", errors="ignore")
|
||||
return len(prefix_chars)
|
||||
|
||||
def includes_byte(self, byte: int) -> bool:
|
||||
return self._byte_offset <= byte <= self._byte_end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user