41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from typing import Optional, List
|
|
|
|
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 HighlightSelection(Highlight):
|
|
start_byte = 0
|
|
end_byte = 0
|
|
|
|
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[List[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, brush=QBrush(QColor(156, 215, 255)), pen=Qt.PenStyle.NoPen)]
|
|
else:
|
|
return None
|