Insert the text at the current cursor position.
356102
def commit(self):
        

        # Backup and remove the currently selected text (may be none).
        tc = self.qteWidget.textCursor()
        self.selText = tc.selection().toHtml()
        self.selStart = tc.selectionStart()
        self.selEnd = tc.selectionEnd()
        tc.removeSelectedText()

        # Move to the start of the (just deleted) text block and insert
        # the characters there.
        tc.setPosition(self.selStart)

        # If the MIME data contained an image then create a new HTML
        # resource for it and insert it with the HTML syntax for adding
        # an image. On the other hand, if the resource was simply a string,
        # then just add it.
        if self.isImage:
            imgName = "pastedImage_{}".format(str(self.pasteCnt))
            document = self.qteWidget.document()
            document.addResource(QtGui.QTextDocument.ImageResource,
                                 QtCore.QUrl(imgName), self.data)
            self.qteWidget.setDocument(document)
            tc.insertHtml('<img src={}>'.format(imgName))
        else:
            tc.insertText(self.data)

        # Update the text cursor in the document.
        self.qteWidget.setTextCursor(tc)
887098
def _cursor_forward(self, value):
        
        if value <= 0:
            value = 1
        self._cursor.movePosition(self._cursor.Right, self._cursor.MoveAnchor, value)
        self._text_edit.setTextCursor(self._cursor)
        self._last_cursor_pos = self._cursor.position()
1220515
def _cursor_down(self, value):
        
        self._cursor.clearSelection()
        if self._cursor.atEnd():
            self._cursor.insertText('\n')
        else:
            self._cursor.movePosition(self._cursor.Down, self._cursor.MoveAnchor, value)
        self._last_cursor_pos = self._cursor.position()
1116377
def indent(self):
        
        cursor = self.editor.textCursor()
        assert isinstance(cursor, QtGui.QTextCursor)
        if cursor.hasSelection():
            self.indent_selection(cursor)
        else:
            # simply insert indentation at the cursor position
            tab_len = self.editor.tab_length
            if cursor.positionInBlock() < self.min_column and not cursor.atBlockEnd():
                cursor.movePosition(cursor.Right, cursor.MoveAnchor, self.min_column)
            cursor.beginEditBlock()
            if self.editor.use_spaces_instead_of_tabs:
                nb_space_to_add = tab_len - (cursor.positionInBlock() - self.min_column) % tab_len
                cursor.insertText(nb_space_to_add * " ")
            else:
                cursor.insertText('\t')
            cursor.endEditBlock()
            self.editor.setTextCursor(cursor)
1164785
def insert_line_below(self, copy_margin=True):
        
        if copy_margin:
            insert = '\n' + self.document.leading_whitespace_in_current_line
        else:
            insert = '\n'

        self.cursor_position += self.document.get_end_of_line_position()
        self.insert_text(insert)
1343816
def placeCursor(self, pos):
        
        if pos > len(self.qteWidget.toPlainText()):
            pos = len(self.qteWidget.toPlainText())

        tc = self.qteWidget.textCursor()
        tc.setPosition(pos)
        self.qteWidget.setTextCursor(tc)
326271
def placeCursor(self, line, col):
        
        num_lines, num_col = self.qteWidget.getNumLinesAndColumns()

        # Place the cursor at the specified position if possible.
        if line >= num_lines:
            line, col = num_lines, num_col
        else:
            text = self.qteWidget.text(line)
            if col >= len(text):
                col = len(text) - 1

        self.qteWidget.setCursorPosition(line, col)
896410
def cursor_position_changed(self):
        """"""
        log.debug("cursor_position_changed")

        cur = self.textCursor()
        log.debug(cur.position())
        log.debug(cur.selectedText())
        if len(cur.selectedText()) == 0:
            cur.select(QtGui.QTextCursor.WordUnderCursor)
            self.setTextCursor(cur)
1074168
def yank(self):
        
        text = self._ring.yank()
        if text:
            self._skip_cursor = True
            cursor = self._text_edit.textCursor()
            cursor.insertText(text)
            self._prev_yank = text
1152133
def set_line_text(self, line_nbr, new_text):
        
        editor = self._editor
        text_cursor = self._move_cursor_to(line_nbr)
        text_cursor.select(text_cursor.LineUnderCursor)
        text_cursor.insertText(new_text)
        editor.setTextCursor(text_cursor)
483244
def _insert_command(self, command):
        
        self._clear_user_buffer()
        tc = self.edit.textCursor()
        tc.insertText(command)
        self.edit.setTextCursor(tc)
206620
def setText(self, sequence):
        """"""
        self.setToolTip(sequence)
        super(ShortcutLineEdit, self).setText(sequence)
632018
def adjustText(self):
        
        pos = self.cursorPosition()
        self.blockSignals(True)
        super(XLineEdit, self).setText(self.formatText(self.text()))
        self.setCursorPosition(pos)
        self.blockSignals(False)
30695
private void addText(TextCursor cursor, int limit, ArrayList<MDText> elements) {
        if (cursor.currentOffset < limit) {
            elements.add(new MDRawText(cursor.text.substring(cursor.currentOffset, limit)));
            cursor.currentOffset = limit;
        }
    }
145549
def cursor_pos(self):
        """"""
        if len(self) == 0:
            return self.left + self.default_text.get_width()

        papy = self._surface.get_width()
        if papy > self.w:
            shift = papy - self.width
        else:
            shift = 0

        return self.left + self.font.size(self.shawn_text[:self.cursor])[0] - shift
97516
def add_text(self, text):
        """"""
        index = self.findText(text)
        while index != -1:
            self.removeItem(index)
            index = self.findText(text)
        self.insertItem(0, text)
        index = self.findText('')
        if index != -1:
            self.removeItem(index)
            self.insertItem(0, '')
            if text != '':
                self.setCurrentIndex(1)
            else:
                self.setCurrentIndex(0)
        else:
            self.setCurrentIndex(0)
356505
def insert(self, index, text):
        
        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)