correctly highlight lines with tabs
This commit is contained in:
30
line.py
30
line.py
@@ -1,3 +1,6 @@
|
||||
import constants
|
||||
|
||||
|
||||
class Line:
|
||||
def __init__(self, byte_offset: int, byte_end: int, line: str):
|
||||
self._byte_offset = byte_offset
|
||||
@@ -24,12 +27,37 @@ class Line:
|
||||
prefix_chars = prefix_bytes.decode("utf8", errors="ignore")
|
||||
return len(prefix_chars)
|
||||
|
||||
def column_to_char(self, column_in_line: int) -> int:
|
||||
i = 0
|
||||
result = 0
|
||||
while i < column_in_line:
|
||||
char = self._line[result]
|
||||
if char == "\t":
|
||||
i = i + constants.tab_width - 1 # jump the additional 7 columns of the tab width
|
||||
if i >= column_in_line:
|
||||
break;
|
||||
i = i + 1
|
||||
result = result + 1
|
||||
|
||||
return result
|
||||
|
||||
def char_to_column(self, char_in_line: int) -> int:
|
||||
result = 0
|
||||
i = 0
|
||||
while i < char_in_line:
|
||||
if i < len(self._line) and self._line[i] == "\t":
|
||||
result = result + constants.tab_width
|
||||
else:
|
||||
result = result + 1
|
||||
i = i + 1
|
||||
return result
|
||||
|
||||
def includes_byte(self, byte: int) -> bool:
|
||||
return self._byte_offset <= byte <= self._byte_end
|
||||
|
||||
def intersects(self, start_byte: int, end_byte: int):
|
||||
result = start_byte < self._byte_end and end_byte > self._byte_offset
|
||||
#print("%d,%d in %d,%d" % (start_byte, end_byte, self._byte_offset, self._byte_end))
|
||||
# print("%d,%d in %d,%d" % (start_byte, end_byte, self._byte_offset, self._byte_end))
|
||||
return result
|
||||
|
||||
def prefix(self, index: int) -> str:
|
||||
|
||||
Reference in New Issue
Block a user