code: 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()
docs: Duplicate selected text or current line