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
+4 -2
View File
@@ -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