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

View File

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