improve highlighting
This commit is contained in:
42
highlight_selection.py
Normal file
42
highlight_selection.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from typing import Optional
|
||||
|
||||
from highlight import Highlight
|
||||
from highlighted_range import HighlightedRange
|
||||
from line import Line
|
||||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from settings import Settings
|
||||
|
||||
|
||||
class HightlightSelection(Highlight):
|
||||
|
||||
def __init__(self, start_byte: int, end_byte: int):
|
||||
self.start_byte = start_byte
|
||||
self.end_byte = end_byte
|
||||
|
||||
def set_start(self, start_byte):
|
||||
self.start_byte = start_byte
|
||||
|
||||
def set_end_byte(self, end_byte):
|
||||
self.end_byte = end_byte
|
||||
|
||||
def compute_highlight(self, line: Line) -> Optional[HighlightedRange]:
|
||||
begin = min(self.start_byte, self.end_byte)
|
||||
end = max(self.start_byte, self.end_byte)
|
||||
|
||||
if line.intersects(begin, end):
|
||||
if line.includes_byte(begin):
|
||||
start = begin - line.byte_offset()
|
||||
else:
|
||||
start = 0
|
||||
|
||||
if line.includes_byte(end):
|
||||
length = end - line.byte_offset() - start
|
||||
else:
|
||||
length = Settings.max_line_length() -start
|
||||
|
||||
return HighlightedRange(start, length, QBrush(QColor(255, 255, 0)), Qt.PenStyle.NoPen)
|
||||
else:
|
||||
return None
|
||||
Reference in New Issue
Block a user