Handle Shift-Return keypresses correctly.

This commit is contained in:
Florian Bruhin 2014-08-30 14:38:34 +02:00
parent c0a88bf3d0
commit e163478782
2 changed files with 16 additions and 1 deletions

View File

@ -705,6 +705,7 @@ DATA = collections.OrderedDict([
('<Tab>', 'completion-item-next'),
('<Down>', 'completion-item-next'),
('<Return>', 'command-accept'),
('<Shift-Return>', 'command-accept'),
('<Ctrl-B>', 'rl-backward-char'),
('<Ctrl-F>', 'rl-forward-char'),
('<Alt-B>', 'rl-backward-word'),
@ -726,6 +727,7 @@ DATA = collections.OrderedDict([
typ.KeyBindingName(), typ.KeyBinding(),
('<Escape>', 'leave-mode'),
('<Return>', 'prompt-accept'),
('<Shift-Return>', 'prompt-accept'),
('y', 'prompt-yes'),
('n', 'prompt-no'),
('<Ctrl-B>', 'rl-backward-char'),

View File

@ -19,7 +19,7 @@
"""The commandline in the statusbar."""
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt
from PyQt5.QtWidgets import QSizePolicy, QApplication
from qutebrowser.keyinput import modeman, modeparsers
@ -305,3 +305,16 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
raise AssertionError("setText got called with invalid text "
"'{}'!".format(text))
super().setText(text)
def keyPressEvent(self, e):
"""Override keyPressEvent to ignore Return key presses.
If this widget is focused, we are in passthrough key mode, and
Enter/Shift+Enter/etc. will cause QLineEdit to think it's finished
without command_accept to be called.
"""
if e.key() == Qt.Key_Return:
e.ignore()
return
else:
super().keyPressEvent(e)