From 294bf51f8a9ab3a6a783618b114bcfef190cc374 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 17 Mar 2024 18:15:02 +0100 Subject: [PATCH] Cap outline to 30 items --- novelwriter/gui/doceditor.py | 4 +++- novelwriter/gui/docviewer.py | 2 +- novelwriter/gui/editordocument.py | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index b229827a..a3051647 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -1194,7 +1194,7 @@ class GuiDocEditor(QPlainTextEdit): SHARED.runInThreadPool(self.wCounterDoc) self.docHeader.setOutline({ block.blockNumber(): block.text() - for block in self._qDocument.iterBlockByType(BLOCK_TITLE) + for block in self._qDocument.iterBlockByType(BLOCK_TITLE, maxCount=30) }) return @@ -1306,6 +1306,7 @@ class GuiDocEditor(QPlainTextEdit): self._docHandle, wrapAround=self.docSearch.doLoop ) self.beginSearch() + self.setFocus() return cursor = self.textCursor() @@ -1326,6 +1327,7 @@ class GuiDocEditor(QPlainTextEdit): self._docHandle, wrapAround=self.docSearch.doLoop ) self.beginSearch() + self.setFocus() return else: resIdx = 0 if doLoop else maxIdx diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index eab156ec..d3352720 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -756,7 +756,7 @@ class GuiDocViewHeader(QWidget): if title != "T0000": entries.append((title, text, level)) minLevel = min(minLevel, level) - for title, text, level in entries: + for title, text, level in entries[:30]: indent = " "*(level - minLevel) action = self.outlineMenu.addAction(f"{indent}{text}") action.triggered.connect( diff --git a/novelwriter/gui/editordocument.py b/novelwriter/gui/editordocument.py index bfefd027..421e89a0 100644 --- a/novelwriter/gui/editordocument.py +++ b/novelwriter/gui/editordocument.py @@ -114,11 +114,13 @@ class GuiTextDocument(QTextDocument): return word, cPos, cLen, SHARED.spelling.suggestWords(word) return "", -1, -1, [] - def iterBlockByType(self, cType: int) -> Generator[QTextBlock]: + def iterBlockByType(self, cType: int, maxCount: int = 1000) -> Generator[QTextBlock]: """Iterate over all text blocks of a given type.""" + count = 0 for i in range(self.blockCount()): block = self.findBlockByNumber(i) - if block.isValid() and block.userState() & cType > 0: + if count < maxCount and block.isValid() and block.userState() & cType > 0: + count += 1 yield block return None