From bff0efb4a4a8381152ba8a479662bb71e5e7ed70 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 17 Oct 2014 15:01:08 +0200 Subject: [PATCH] Paste primary selection on Shift+Insert --- qutebrowser/widgets/misc.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/qutebrowser/widgets/misc.py b/qutebrowser/widgets/misc.py index 6232848b0..b212ffa78 100644 --- a/qutebrowser/widgets/misc.py +++ b/qutebrowser/widgets/misc.py @@ -20,8 +20,8 @@ """Misc. widgets used at different places.""" from PyQt5.QtCore import pyqtSlot, Qt -from PyQt5.QtWidgets import QLineEdit -from PyQt5.QtGui import QValidator +from PyQt5.QtWidgets import QLineEdit, QApplication +from PyQt5.QtGui import QValidator, QClipboard from qutebrowser.models import cmdhistory from qutebrowser.utils import utils @@ -64,6 +64,9 @@ class CommandLineEdit(QLineEdit): self.cursorPositionChanged.connect(self.__on_cursor_position_changed) self._promptlen = 0 + def __repr__(self): + return utils.get_repr(self, text=self.text()) + @pyqtSlot(str) def on_text_edited(self, _text): """Slot for textEdited. Stop history browsing.""" @@ -94,8 +97,16 @@ class CommandLineEdit(QLineEdit): if mark: self.setSelection(self._promptlen, oldpos - self._promptlen) - def __repr__(self): - return utils.get_repr(self, text=self.text()) + def keyPressEvent(self, e): + """Override keyPressEvent to paste primary selection on Shift + Ins.""" + if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier: + clipboard = QApplication.clipboard() + if clipboard.supportsSelection(): + e.accept() + text = clipboard.text(QClipboard.Selection) + self.insert(text) + return + super().keyPressEvent(e) class _CommandValidator(QValidator):