From cbc79d70820d4874ab5de04a57275364d8f18446 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 14 Jun 2025 17:30:30 +0200 Subject: [PATCH] Merge line highlight with existing signal handler for cursor move --- novelwriter/gui/doceditor.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index c7b1e6a2..5e49d67e 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -234,9 +234,6 @@ class GuiDocEditor(QPlainTextEdit): self.updateSyntaxColors() self.initEditor() - # Connect Additional Signal - self.cursorPositionChanged.connect(self._highlightCurrentLine) - logger.debug("Ready: GuiDocEditor") return @@ -383,7 +380,7 @@ class GuiDocEditor(QPlainTextEdit): self.setTabStopDistance(CONFIG.tabWidth) self.setCursorWidth(CONFIG.cursorWidth) self.setExtraSelections([]) - self._highlightCurrentLine() + self._cursorMoved() # If we have a document open, we should refresh it in case the # font changed, otherwise we just clear the editor entirely, @@ -1122,6 +1119,10 @@ class GuiDocEditor(QPlainTextEdit): def _cursorMoved(self) -> None: """Triggered when the cursor moved in the editor.""" self.docFooter.updateLineCount(self.textCursor()) + if CONFIG.lineHighlight: + self._selection.cursor = self.textCursor() + self._selection.cursor.clearSelection() + self.setExtraSelections([self._selection]) return @pyqtSlot(int, int, str) @@ -1313,15 +1314,6 @@ class GuiDocEditor(QPlainTextEdit): CONFIG.showEditToolBar = state return - @pyqtSlot() - def _highlightCurrentLine(self) -> None: - """Highlight the cursor line if setting is enabled.""" - if CONFIG.lineHighlight: - self._selection.cursor = self.textCursor() - self._selection.cursor.clearSelection() - self.setExtraSelections([self._selection]) - return - ## # Search & Replace ##