def _get_format_from_document( self, token: str, document: QtGui.QTextDocument) -> QtGui.QTextCharFormat: """Return a QTextCharFormat for token from document.""" code, html = next(self._formatter._format_lines([(token, "dummy")])) self._document.setHtml(html) return gui.TextCursor(self._document).charFormat()
def test_textcursor(): cursor = gui.TextCursor() cursor.set_position(1, "move") cursor.move_position("start", "move", 1) cursor.select("document") cursor.replace_text(0, 2, "test") cursor.select_text(1, 3) cursor.span() with cursor.edit_block(): pass
def get_text_cursor(self) -> gui.TextCursor: return gui.TextCursor(self.textCursor())
def create_cursor(self) -> Iterator[gui.TextCursor]: cursor = gui.TextCursor(self.document()) yield cursor self.setTextCursor(cursor)
def current_cursor(self) -> Iterator[gui.TextCursor]: cursor = gui.TextCursor(self.textCursor()) yield cursor self.setTextCursor(cursor)
def get_last_cursor_position(self) -> gui.TextCursor: return gui.TextCursor(self.lastCursorPosition())