Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions typstwriter/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,15 @@ 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()
highlights.append(mark_line)

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)

Expand Down
14 changes: 14 additions & 0 deletions typstwriter/syntax_highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down