Insert the text at the current cursor position.

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

        tc = self.qteWidget.textCursor()

        # If this is the first ever call to this undo/redo element then
        # backup the current cursor position and the selected text (may be
        # none). This information will be required for the redo operation
        # to position the cursor (and selected text) where it was at the
        # very first call.
        if self.cursorPos0 is None:
            self.cursorPos0 = tc.position()
            self.selText = tc.selection().toHtml()
            self.selStart = tc.selectionStart()
            self.selEnd = tc.selectionEnd()
        else:
            tc.setPosition(self.cursorPos0, QtGui.QTextCursor.MoveAnchor)

        # Remove the originally selected text (may be none).
        tc.setPosition(self.selStart, QtGui.QTextCursor.MoveAnchor)
        tc.setPosition(self.selEnd, QtGui.QTextCursor.KeepAnchor)
        tc.removeSelectedText()

        # Move to the start of the (just deleted) text block and insert
        # the characters there.
        if len(self.selText) > 0:
            pos = self.selStart
        else:
            pos = tc.position()
        tc.setPosition(pos)

        # Backup the cursor position before the insertion operation,
        # insert the new character(s), move the cursor forward, and
        # backup the new cursor position as well.
        self.cursorPos1 = tc.position()
        tc.insertText(self.text)
        self.cursorPos2 = tc.position()

        self.qteWidget.setTextCursor(tc)