From 6c18b0264251888a51f737d6dd50570f1fda1817 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 18 Jan 2024 20:02:34 +0530 Subject: [PATCH] Only highlight cursor line after syntax highlighter is finished This is because cursor line highlight relies on data from syntax highlighting (to apply background colors) --- src/calibre/gui2/tweak_book/editor/text.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index ae33506339..3fb2c1da44 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -625,6 +625,13 @@ class TextEdit(PlainTextEdit): # Line numbers and cursor line {{{ def highlight_cursor_line(self): + self._highlight_cursor_line() + + def _highlight_cursor_line(self, highlight_now=True): + if self.highlighter.is_working: + QTimer.singleShot(10, self.highlight_cursor_line) + if not highlight_now: + return sel = QTextEdit.ExtraSelection() sel.format.setBackground(self.palette().alternateBase()) sel.format.setProperty(QTextFormat.Property.FullWidthSelection, True) @@ -632,7 +639,7 @@ class TextEdit(PlainTextEdit): sel.cursor.clearSelection() self.current_cursor_line = [sel] - # apply any formats that have a backgroud over the cursor line format + # apply any formats that have a background over the cursor line format # to ensure they are visible c = self.textCursor() block = c.block()