highlight other matches of selected text

This commit is contained in:
2022-08-26 15:31:45 +02:00
parent 6040b1633d
commit bbedaf73de
2 changed files with 38 additions and 1 deletions

View File

@@ -29,6 +29,10 @@ class HighlightRegex(Highlight):
else:
return re.compile(re.escape(self.query), flags=flags)
def set_query(self, query: str) -> None:
self.query = query
self.regex = self._get_regex()
def compute_highlight(self, line: Line) -> Optional[List[HighlightedRange]]:
result = []
# print("execute regex: %s in %s" % (self.regex, line.line()))
@@ -56,9 +60,15 @@ class HighlightRegex(Highlight):
@staticmethod
def brush(color: str) -> QBrush:
if re.match("[0-9a-f]{6}", color, flags=re.IGNORECASE):
if re.match("^[0-9a-f]{6}$", color, flags=re.IGNORECASE):
red = int(color[0:2], 16)
green = int(color[2:4], 16)
blue = int(color[4:6], 16)
return QBrush(QColor(red, green, blue))
if re.match("^[0-9a-f]{8}$", color, flags=re.IGNORECASE):
red = int(color[0:2], 16)
green = int(color[2:4], 16)
blue = int(color[4:6], 16)
alpha = int(color[6:8], 16)
return QBrush(QColor(red, green, blue, alpha))
return QBrush()