Beispiel #1
0
 def setLine(self, line):
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.End)
     cursor.setPosition(self.newPromptPos, QTextCursor.KeepAnchor)
     cursor.removeSelectedText()
     cursor.insertText(line)
     self.setTextCursor(cursor)
Beispiel #2
0
 def setLine(self, line):
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.End)
     cursor.setPosition(self.newPromptPos, QTextCursor.KeepAnchor)
     cursor.removeSelectedText()
     cursor.insertText(line)
     self.setTextCursor(cursor)
Beispiel #3
0
 def append(self, text):
     """Append line to the end
     """
     cursor = QTextCursor(self._doc)
     cursor.movePosition(QTextCursor.End)
     cursor.insertBlock()
     cursor.insertText(text)
Beispiel #4
0
    def cmdJoinLines(self, cmd, repeatLineCount=None):
        if repeatLineCount is not None:
            self._selectRangeForRepeat(repeatLineCount)

        start, end = self._selectedLinesRange()
        count = end - start

        if not count:  # nothing to join
            return

        self._saveLastEditLinesCmd(cmd, end - start + 1)

        cursor = QTextCursor(self._qpart.document().findBlockByNumber(start))
        with self._qpart:
            for _ in range(count):
                cursor.movePosition(QTextCursor.EndOfBlock)
                cursor.movePosition(QTextCursor.NextCharacter,
                                    QTextCursor.KeepAnchor)
                self.moveToFirstNonSpace(cursor, QTextCursor.KeepAnchor)
                nonEmptyBlock = cursor.block().length() > 1
                cursor.removeSelectedText()
                if nonEmptyBlock:
                    cursor.insertText(' ')

        self._qpart.setTextCursor(cursor)
Beispiel #5
0
    def insert(self, index, text):
        """Insert line to the document
        """
        if index < 0 or index > self._doc.blockCount():
            raise IndexError('Invalid block index', index)

        if index == 0:  # first
            cursor = QTextCursor(self._doc.firstBlock())
            cursor.insertText(text)
            cursor.insertBlock()
        elif index != self._doc.blockCount():  # not the last
            cursor = QTextCursor(self._doc.findBlockByNumber(index).previous())
            cursor.movePosition(QTextCursor.EndOfBlock)
            cursor.insertBlock()
            cursor.insertText(text)
        else:  # last append to the end
            self.append(text)
Beispiel #6
0
 def _removeBlock(blockIndex):
     block = self._doc.findBlockByNumber(blockIndex)
     if block.next().isValid():  # not the last
         cursor = QTextCursor(block)
         cursor.movePosition(QTextCursor.NextBlock,
                             QTextCursor.KeepAnchor)
     elif block.previous().isValid():  # the last, not the first
         cursor = QTextCursor(block.previous())
         cursor.movePosition(QTextCursor.EndOfBlock)
         cursor.movePosition(QTextCursor.NextBlock,
                             QTextCursor.KeepAnchor)
         cursor.movePosition(QTextCursor.EndOfBlock,
                             QTextCursor.KeepAnchor)
     else:  # only one block
         cursor = QTextCursor(block)
         cursor.movePosition(QTextCursor.EndOfBlock,
                             QTextCursor.KeepAnchor)
     cursor.removeSelectedText()
Beispiel #7
0
 def write(self, data):
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
     cursor.insertText(data)
     self.setTextCursor(cursor)
     self.ensureCursorVisible()
Beispiel #8
0
 def write(self, data):
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
     cursor.insertText(data)
     self.setTextCursor(cursor)
     self.ensureCursorVisible()
Beispiel #9
0
 def textCursor(self) -> QTextCursor:
     """Return a text cursor positioned at the end of the document."""
     cursor = QTextCursor(self)
     cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
     cursor.setCharFormat(self.__currentCharFormat)
     return cursor
Beispiel #10
0
 def _setBlockText(blockIndex, text):
     cursor = QTextCursor(self._doc.findBlockByNumber(blockIndex))
     cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
     cursor.insertText(text)