diff --git a/typstwriter/editor.py b/typstwriter/editor.py index 2b055e0..d8cef2a 100644 --- a/typstwriter/editor.py +++ b/typstwriter/editor.py @@ -902,7 +902,7 @@ def highlight_errors(self, errors): cursor.movePosition(QtGui.QTextCursor.MoveOperation.Right, QtGui.QTextCursor.MoveMode.KeepAnchor, length) mark_line = QtWidgets.QTextEdit.ExtraSelection() - mark_line.format.setBackground(QtGui.QColor("#ffeeee")) + mark_line.format.setBackground(QtGui.QColor(self.highlighter.error_highlight_color)) mark_line.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True) mark_line.cursor = cursor mark_line.cursor.clearSelection() @@ -910,7 +910,7 @@ def highlight_errors(self, errors): mark_span = QtWidgets.QTextEdit.ExtraSelection() mark_span.format.setUnderlineStyle(QtGui.QTextCharFormat.DashUnderline) - mark_span.format.setUnderlineColor("#cc1b1b") + mark_span.format.setUnderlineColor(QtGui.QColor(self.highlighter.error_font_color)) mark_span.cursor = cursor highlights.append(mark_span) diff --git a/typstwriter/syntax_highlighting.py b/typstwriter/syntax_highlighting.py index f43b8b4..5ebfcf0 100644 --- a/typstwriter/syntax_highlighting.py +++ b/typstwriter/syntax_highlighting.py @@ -138,6 +138,20 @@ def line_number_special_background_color(self): """Line number special background color.""" return self.formatter.style.line_number_special_background_color + @property + def error_font_color(self): + """Font color for error tokens.""" + return self.formatter.style.styles[pygments.token.Error] + + @property + def error_highlight_color(self): + """Color for highlighting errors.""" + # Use the same saturation, value (brightness) and alpha as standard highlight color, but use hue 0 (red). + # This ensures decent readability on most themes while being distinct from the standard highlight color. + color = QtGui.QColor(self.highlight_color) + color.setHsv(0, color.saturation(), color.value(), color.alpha()) + return color.name(QtGui.QColor.HexRgb) + def highlightBlock(self, text): # This is an overriding function # noqa: N802 """Highlight the given text block.""" format_list = self.formatter.format(pygments.lex(text, self.lexer), None)