(self)
Duplicate selected text or current line
Duplicate selected text or current line
Duplicate selected text or current line
def _onShortcutDuplicateLine(self):
        """Duplicate selected text or current line
        """
        cursor = self.textCursor()
        if cursor.hasSelection():  # duplicate selection
            text = cursor.selectedText()
            selectionStart, selectionEnd = cursor.selectionStart(), cursor.selectionEnd()
            cursor.setPosition(selectionEnd)
            cursor.insertText(text)
            # restore selection
            cursor.setPosition(selectionStart)
            cursor.setPosition(selectionEnd, QTextCursor.KeepAnchor)
            self.setTextCursor(cursor)
        else:
            line = cursor.blockNumber()
            self.lines.insert(line + 1, self.lines[line])
            self.ensureCursorVisible()

        self._updateExtraSelections()
def _onShortcutDuplicateLine ( self ) : cursor = self . textCursor ( ) if cursor . hasSelection ( ) : # duplicate selection text = cursor . selectedText ( ) selectionStart , selectionEnd = cursor . selectionStart ( ) , cursor . selectionEnd ( ) cursor . setPosition ( selectionEnd ) cursor . insertText ( text ) # restore selection cursor . setPosition ( selectionStart ) cursor . setPosition ( selectionEnd , QTextCursor . KeepAnchor ) self . setTextCursor ( cursor ) else : line = cursor . blockNumber ( ) self . lines . insert ( line + 1 , self . lines [ line ] ) self . ensureCursorVisible ( ) self . _updateExtraSelections ( )