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

        # 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)