Cap outline to 30 items
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user