Make hints work

This commit is contained in:
Florian Bruhin 2018-02-26 10:33:18 +01:00
parent be4cd94207
commit 9aa37febbe
2 changed files with 21 additions and 14 deletions

View File

@ -61,6 +61,7 @@ class BaseKeyParser(QObject):
_sequence: The currently entered key sequence
_modename: The name of the input mode associated with this keyparser.
_supports_count: Whether count is supported
# FIXME is this still needed?
_supports_chains: Whether keychains are supported
Signals:
@ -138,7 +139,7 @@ class BaseKeyParser(QObject):
# self._debug_log("Ignoring, no text char")
# return QKeySequence.NoMatch
if txt.isdigit():
if txt.isdigit() and self._supports_count:
assert len(txt) == 1, txt
self._count += txt
return None

View File

@ -213,8 +213,9 @@ class HintKeyParser(keyparser.CommandKeyParser):
True if the match has been handled, False otherwise.
"""
# FIXME rewrite this
match = super().handle(e)
match = self._handle_key(e)
if match == QKeySequence.PartialMatch:
# FIXME do we need to check self._sequence here?
self.keystring_updated.emit(str(self._sequence))
self._last_press = LastPress.keystring
return True
@ -229,17 +230,20 @@ class HintKeyParser(keyparser.CommandKeyParser):
else:
raise ValueError("Got invalid match type {}!".format(match))
def execute(self, cmdstr, keytype, count=None):
"""Handle a completed keychain."""
if not isinstance(keytype, self.Type):
raise TypeError("Type {} is no Type member!".format(keytype))
if keytype == self.Type.chain:
hintmanager = objreg.get('hintmanager', scope='tab',
window=self._win_id, tab='current')
hintmanager.handle_partial_key(cmdstr)
else:
# execute as command
super().execute(cmdstr, keytype, count)
return match != QKeySequence.NoMatch
# FIXME why is this needed?
# def execute(self, cmdstr, keytype, count=None):
# """Handle a completed keychain."""
# if not isinstance(keytype, self.Type):
# raise TypeError("Type {} is no Type member!".format(keytype))
# if keytype == self.Type.chain:
# hintmanager = objreg.get('hintmanager', scope='tab',
# window=self._win_id, tab='current')
# hintmanager.handle_partial_key(cmdstr)
# else:
# # execute as command
# super().execute(cmdstr, keytype, count)
def update_bindings(self, strings, preserve_filter=False):
"""Update bindings when the hint strings changed.
@ -249,7 +253,9 @@ class HintKeyParser(keyparser.CommandKeyParser):
preserve_filter: Whether to keep the current value of
`self._filtertext`.
"""
self.bindings = {keyutils.KeySequence(s): s for s in strings}
self._read_config()
self.bindings.update({keyutils.KeySequence(s):
'follow-hint ' + s for s in strings})
if not preserve_filter:
self._filtertext = ''