From 6b69dbb8e4ba6e63049a9801ee1b3865e1bc2a8e Mon Sep 17 00:00:00 2001 From: Theophile Gilgien Date: Sun, 10 Aug 2025 16:19:00 +0200 Subject: [PATCH 1/4] Use style-dependent colour to highlight errors --- typstwriter/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typstwriter/editor.py b/typstwriter/editor.py index 2b055e0..8bc9b69 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.highlight_color)) mark_line.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True) mark_line.cursor = cursor mark_line.cursor.clearSelection() From ad194864fb98c560cf49772dba81846236713c24 Mon Sep 17 00:00:00 2001 From: Theophile Gilgien Date: Fri, 15 Aug 2025 17:10:49 +0200 Subject: [PATCH 2/4] use theme's error colour for error underlining --- typstwriter/editor.py | 2 +- typstwriter/syntax_highlighting.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/typstwriter/editor.py b/typstwriter/editor.py index 8bc9b69..a0fb7de 100644 --- a/typstwriter/editor.py +++ b/typstwriter/editor.py @@ -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..b5da14b 100644 --- a/typstwriter/syntax_highlighting.py +++ b/typstwriter/syntax_highlighting.py @@ -138,6 +138,11 @@ 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 tockens.""" + return self.formatter.style.styles[pygments.token.Error] + 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) From 8aba127ccd9a324503bb93d2e4a8f1eadc065b3c Mon Sep 17 00:00:00 2001 From: Theophile Gilgien Date: Sat, 23 Aug 2025 16:19:39 +0200 Subject: [PATCH 3/4] introduce specific error highlighting color --- typstwriter/editor.py | 2 +- typstwriter/syntax_highlighting.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/typstwriter/editor.py b/typstwriter/editor.py index a0fb7de..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(self.highlighter.highlight_color)) + 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() diff --git a/typstwriter/syntax_highlighting.py b/typstwriter/syntax_highlighting.py index b5da14b..61c7ae9 100644 --- a/typstwriter/syntax_highlighting.py +++ b/typstwriter/syntax_highlighting.py @@ -143,6 +143,15 @@ def error_font_color(self): """Font color for error tockens.""" 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) From 4d09fcacd5f892fc0309ba0616e170ac886661b2 Mon Sep 17 00:00:00 2001 From: Bzero Date: Sat, 23 Aug 2025 19:54:08 +0200 Subject: [PATCH 4/4] Update syntax_highlighting.py Small typo. --- typstwriter/syntax_highlighting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typstwriter/syntax_highlighting.py b/typstwriter/syntax_highlighting.py index 61c7ae9..5ebfcf0 100644 --- a/typstwriter/syntax_highlighting.py +++ b/typstwriter/syntax_highlighting.py @@ -140,7 +140,7 @@ def line_number_special_background_color(self): @property def error_font_color(self): - """Font color for error tockens.""" + """Font color for error tokens.""" return self.formatter.style.styles[pygments.token.Error] @property