Merge branch 'keyinput' of https://github.com/lahwaacz/qutebrowser into lahwaacz-keyinput

This commit is contained in:
Florian Bruhin 2016-08-11 19:46:30 +02:00
commit 9c67e87c37
4 changed files with 18 additions and 12 deletions

View File

@ -1452,7 +1452,7 @@ RETURN_KEYS = ['<Return>', '<Ctrl-M>', '<Ctrl-J>', '<Shift-Return>', '<Enter>',
KEY_DATA = collections.OrderedDict([
('!normal', collections.OrderedDict([
('clear-keychain ;; leave-mode', ['<Escape>', '<Ctrl-[>']),
('leave-mode', ['<Escape>', '<Ctrl-[>']),
])),
('normal', collections.OrderedDict([
@ -1683,7 +1683,7 @@ CHANGED_KEY_COMMANDS = [
(re.compile(r'^scroll ([-\d]+ [-\d]+)$'), r'scroll-px \1'),
(re.compile(r'^search *;; *clear-keychain$'), r'clear-keychain ;; search'),
(re.compile(r'^leave-mode$'), r'clear-keychain ;; leave-mode'),
(re.compile(r'^clear-keychain *;; *leave-mode$'), r'leave-mode'),
(re.compile(r'^download-remove --all$'), r'download-clear'),

View File

@ -193,7 +193,7 @@ class BaseKeyParser(QObject):
if match == self.Match.definitive:
self._debug_log("Definitive match for '{}'.".format(
self._keystring))
self._keystring = ''
self.clear_keystring()
self.execute(binding, self.Type.chain, count)
elif match == self.Match.ambiguous:
self._debug_log("Ambiguous match for '{}'.".format(
@ -205,7 +205,7 @@ class BaseKeyParser(QObject):
elif match == self.Match.none:
self._debug_log("Giving up with '{}', no matches".format(
self._keystring))
self._keystring = ''
self.clear_keystring()
else:
raise AssertionError("Invalid match value {!r}".format(match))
return match
@ -271,7 +271,7 @@ class BaseKeyParser(QObject):
time = config.get('input', 'timeout')
if time == 0:
# execute immediately
self._keystring = ''
self.clear_keystring()
self.execute(binding, self.Type.chain, count)
else:
# execute in `time' ms
@ -289,8 +289,7 @@ class BaseKeyParser(QObject):
command/count: As if passed to self.execute()
"""
self._debug_log("Executing delayed command now!")
self._keystring = ''
self.keystring_updated.emit(self._keystring)
self.clear_keystring()
self.execute(command, self.Type.chain, count)
def handle(self, e):
@ -307,7 +306,9 @@ class BaseKeyParser(QObject):
if handled or not self._supports_chains:
return handled
match = self._handle_single_key(e)
self.keystring_updated.emit(self._keystring)
# don't emit twice if the keystring was cleared in self.clear_keystring
if self._keystring:
self.keystring_updated.emit(self._keystring)
return match != self.Match.none
def read_config(self, modename=None):
@ -366,6 +367,8 @@ class BaseKeyParser(QObject):
def clear_keystring(self):
"""Clear the currently entered key sequence."""
self._debug_log("discarding keystring '{}'.".format(self._keystring))
self._keystring = ''
self.keystring_updated.emit(self._keystring)
if self._keystring:
self._debug_log("discarding keystring '{}'.".format(
self._keystring))
self._keystring = ''
self.keystring_updated.emit(self._keystring)

View File

@ -282,6 +282,9 @@ class ModeManager(QObject):
raise NotInModeError("Not in mode {}!".format(mode))
log.modes.debug("Leaving mode {}{}".format(
mode, '' if reason is None else ' (reason: {})'.format(reason)))
# leaving a mode implies clearing keychain, see
# https://github.com/The-Compiler/qutebrowser/issues/1805
self.clear_keychain()
self.mode = usertypes.KeyMode.normal
self.left.emit(mode, self.mode, self._win_id)

View File

@ -278,7 +278,7 @@ class TestKeyConfigParser:
('search ;; clear-keychain', 'clear-keychain ;; search'),
('search;;clear-keychain', 'clear-keychain ;; search'),
('search;;foo', None),
('leave-mode', 'clear-keychain ;; leave-mode'),
('clear-keychain ;; leave-mode', 'leave-mode'),
('leave-mode ;; foo', None),
('download-remove --all', 'download-clear'),