Add document outline generator for editor

This commit is contained in:
Veronica Berglyd Olsen
2024-03-17 12:26:25 +01:00
parent c3aa8fec56
commit 5453d2ada1
3 changed files with 55 additions and 34 deletions
+10 -1
View File
@@ -23,11 +23,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from collections.abc import Generator
import logging
from time import time
from PyQt5.QtGui import QTextCursor, QTextDocument
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextDocument
from PyQt5.QtCore import QObject, pyqtSlot
from PyQt5.QtWidgets import QPlainTextDocumentLayout, qApp
from novelwriter import SHARED
@@ -113,6 +114,14 @@ class GuiTextDocument(QTextDocument):
return word, cPos, cLen, SHARED.spelling.suggestWords(word)
return "", -1, -1, []
def iterBlockByType(self, cType: int) -> Generator[QTextBlock]:
"""Iterate over all text blocks of a given type."""
for i in range(self.blockCount()):
block = self.findBlockByNumber(i)
if block.isValid() and block.userState() & cType > 0:
yield block
return None
##
# Public Slots
##