Return Match instead bool in _handle_single_key.
This commit is contained in:
parent
d66997610b
commit
42e2438efb
@ -71,7 +71,7 @@ class BaseKeyParser(QObject):
|
|||||||
do_log = True
|
do_log = True
|
||||||
|
|
||||||
Match = usertypes.enum('Match', ['partial', 'definitive', 'ambiguous',
|
Match = usertypes.enum('Match', ['partial', 'definitive', 'ambiguous',
|
||||||
'none'])
|
'other', 'none'])
|
||||||
Type = usertypes.enum('Type', ['chain', 'special'])
|
Type = usertypes.enum('Type', ['chain', 'special'])
|
||||||
|
|
||||||
def __init__(self, win_id, parent=None, supports_count=None,
|
def __init__(self, win_id, parent=None, supports_count=None,
|
||||||
@ -153,7 +153,7 @@ class BaseKeyParser(QObject):
|
|||||||
e: the KeyPressEvent from Qt.
|
e: the KeyPressEvent from Qt.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if event has been handled, False otherwise.
|
A self.Match member.
|
||||||
"""
|
"""
|
||||||
txt = e.text()
|
txt = e.text()
|
||||||
key = e.key()
|
key = e.key()
|
||||||
@ -163,7 +163,7 @@ class BaseKeyParser(QObject):
|
|||||||
self._debug_log("Escape pressed, discarding '{}'.".format(
|
self._debug_log("Escape pressed, discarding '{}'.".format(
|
||||||
self._keystring))
|
self._keystring))
|
||||||
self._keystring = ''
|
self._keystring = ''
|
||||||
return
|
return self.Match.none
|
||||||
|
|
||||||
if len(txt) == 1:
|
if len(txt) == 1:
|
||||||
category = unicodedata.category(txt) # pylint: disable=no-member
|
category = unicodedata.category(txt) # pylint: disable=no-member
|
||||||
@ -173,7 +173,7 @@ class BaseKeyParser(QObject):
|
|||||||
|
|
||||||
if (not txt) or is_control_char:
|
if (not txt) or is_control_char:
|
||||||
self._debug_log("Ignoring, no text char")
|
self._debug_log("Ignoring, no text char")
|
||||||
return False
|
return self.Match.none
|
||||||
|
|
||||||
self._stop_delayed_exec()
|
self._stop_delayed_exec()
|
||||||
self._keystring += txt
|
self._keystring += txt
|
||||||
@ -182,7 +182,7 @@ class BaseKeyParser(QObject):
|
|||||||
|
|
||||||
if not cmd_input:
|
if not cmd_input:
|
||||||
# Only a count, no command yet, but we handled it
|
# Only a count, no command yet, but we handled it
|
||||||
return True
|
return self.Match.other
|
||||||
|
|
||||||
match, binding = self._match_key(cmd_input)
|
match, binding = self._match_key(cmd_input)
|
||||||
|
|
||||||
@ -205,8 +205,7 @@ class BaseKeyParser(QObject):
|
|||||||
self._debug_log("Giving up with '{}', no matches".format(
|
self._debug_log("Giving up with '{}', no matches".format(
|
||||||
self._keystring))
|
self._keystring))
|
||||||
self._keystring = ''
|
self._keystring = ''
|
||||||
return False
|
return match
|
||||||
return True
|
|
||||||
|
|
||||||
def _match_key(self, cmd_input):
|
def _match_key(self, cmd_input):
|
||||||
"""Try to match a given keystring with any bound keychain.
|
"""Try to match a given keystring with any bound keychain.
|
||||||
@ -296,13 +295,16 @@ class BaseKeyParser(QObject):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
e: the KeyPressEvent from Qt
|
e: the KeyPressEvent from Qt
|
||||||
|
|
||||||
|
Return:
|
||||||
|
True if the event was handled, False otherwise.
|
||||||
"""
|
"""
|
||||||
handled = self._handle_special_key(e)
|
handled = self._handle_special_key(e)
|
||||||
if handled or not self._supports_chains:
|
if handled or not self._supports_chains:
|
||||||
return handled
|
return handled
|
||||||
handled = self._handle_single_key(e)
|
match = self._handle_single_key(e)
|
||||||
self.keystring_updated.emit(self._keystring)
|
self.keystring_updated.emit(self._keystring)
|
||||||
return handled
|
return match != self.Match.none
|
||||||
|
|
||||||
def read_config(self, modename=None):
|
def read_config(self, modename=None):
|
||||||
"""Read the configuration.
|
"""Read the configuration.
|
||||||
|
@ -54,12 +54,12 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
e: the KeyPressEvent from Qt.
|
e: the KeyPressEvent from Qt.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if event has been handled, False otherwise.
|
A self.Match member.
|
||||||
"""
|
"""
|
||||||
txt = e.text().strip()
|
txt = e.text().strip()
|
||||||
if not self._keystring and any(txt == c for c in STARTCHARS):
|
if not self._keystring and any(txt == c for c in STARTCHARS):
|
||||||
message.set_cmd_text(self._win_id, txt)
|
message.set_cmd_text(self._win_id, txt)
|
||||||
return True
|
return self.Match.definitive
|
||||||
return super()._handle_single_key(e)
|
return super()._handle_single_key(e)
|
||||||
|
|
||||||
|
|
||||||
@ -140,21 +140,25 @@ class HintKeyParser(keyparser.CommandKeyParser):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
e: the KeyPressEvent from Qt
|
e: the KeyPressEvent from Qt
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the match has been handled, False otherwise.
|
||||||
"""
|
"""
|
||||||
handled = self._handle_single_key(e)
|
match = self._handle_single_key(e)
|
||||||
if handled and self._keystring:
|
if match == self.Match.partial:
|
||||||
# A key has been added to the keystring (Match.partial)
|
|
||||||
self.keystring_updated.emit(self._keystring)
|
self.keystring_updated.emit(self._keystring)
|
||||||
self._last_press = LastPress.keystring
|
self._last_press = LastPress.keystring
|
||||||
return handled
|
return True
|
||||||
elif handled:
|
elif match == self.Match.definitive:
|
||||||
# We handled the key but the keystring is empty. This happens when
|
|
||||||
# match is Match.definitive, so a keychain has been completed.
|
|
||||||
self._last_press = LastPress.none
|
self._last_press = LastPress.none
|
||||||
return handled
|
return True
|
||||||
else:
|
elif match == self.Match.other:
|
||||||
|
pass
|
||||||
|
elif match == self.Match.none:
|
||||||
# We couldn't find a keychain so we check if it's a special key.
|
# We couldn't find a keychain so we check if it's a special key.
|
||||||
return self._handle_special_key(e)
|
return self._handle_special_key(e)
|
||||||
|
else:
|
||||||
|
raise ValueError("Got invalid match type {}!".format(match))
|
||||||
|
|
||||||
def execute(self, cmdstr, keytype, count=None):
|
def execute(self, cmdstr, keytype, count=None):
|
||||||
"""Handle a completed keychain."""
|
"""Handle a completed keychain."""
|
||||||
|
Loading…
Reference in New Issue
Block a user