Cap outline to 30 items

This commit is contained in:
Veronica Berglyd Olsen
2024-03-17 18:15:02 +01:00
parent 8133e374d1
commit 294bf51f8a
3 changed files with 8 additions and 4 deletions
+3 -1
View File
@@ -1194,7 +1194,7 @@ class GuiDocEditor(QPlainTextEdit):
SHARED.runInThreadPool(self.wCounterDoc) SHARED.runInThreadPool(self.wCounterDoc)
self.docHeader.setOutline({ self.docHeader.setOutline({
block.blockNumber(): block.text() block.blockNumber(): block.text()
for block in self._qDocument.iterBlockByType(BLOCK_TITLE) for block in self._qDocument.iterBlockByType(BLOCK_TITLE, maxCount=30)
}) })
return return
@@ -1306,6 +1306,7 @@ class GuiDocEditor(QPlainTextEdit):
self._docHandle, wrapAround=self.docSearch.doLoop self._docHandle, wrapAround=self.docSearch.doLoop
) )
self.beginSearch() self.beginSearch()
self.setFocus()
return return
cursor = self.textCursor() cursor = self.textCursor()
@@ -1326,6 +1327,7 @@ class GuiDocEditor(QPlainTextEdit):
self._docHandle, wrapAround=self.docSearch.doLoop self._docHandle, wrapAround=self.docSearch.doLoop
) )
self.beginSearch() self.beginSearch()
self.setFocus()
return return
else: else:
resIdx = 0 if doLoop else maxIdx resIdx = 0 if doLoop else maxIdx
+1 -1
View File
@@ -756,7 +756,7 @@ class GuiDocViewHeader(QWidget):
if title != "T0000": if title != "T0000":
entries.append((title, text, level)) entries.append((title, text, level))
minLevel = min(minLevel, level) minLevel = min(minLevel, level)
for title, text, level in entries: for title, text, level in entries[:30]:
indent = " "*(level - minLevel) indent = " "*(level - minLevel)
action = self.outlineMenu.addAction(f"{indent}{text}") action = self.outlineMenu.addAction(f"{indent}{text}")
action.triggered.connect( action.triggered.connect(
+4 -2
View File
@@ -114,11 +114,13 @@ class GuiTextDocument(QTextDocument):
return word, cPos, cLen, SHARED.spelling.suggestWords(word) return word, cPos, cLen, SHARED.spelling.suggestWords(word)
return "", -1, -1, [] 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.""" """Iterate over all text blocks of a given type."""
count = 0
for i in range(self.blockCount()): for i in range(self.blockCount()):
block = self.findBlockByNumber(i) 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 yield block
return None return None