Move cmd/count splitting out of _handle_single_key
This commit is contained in:
parent
e88ce5e837
commit
db6ab7212f
@ -136,6 +136,21 @@ class BaseKeyParser(QObject):
|
|||||||
self.execute(cmdstr, self.Type.special)
|
self.execute(cmdstr, self.Type.special)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _split_count(self):
|
||||||
|
"""Get count and command from the current keystring.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
A (count, command) tuple.
|
||||||
|
"""
|
||||||
|
if self._supports_count:
|
||||||
|
(countstr, cmd_input) = re.match(r'^(\d*)(.*)',
|
||||||
|
self._keystring).groups()
|
||||||
|
count = int(countstr) if countstr else None
|
||||||
|
else:
|
||||||
|
cmd_input = self._keystring
|
||||||
|
count = None
|
||||||
|
return count, cmd_input
|
||||||
|
|
||||||
def _handle_single_key(self, e):
|
def _handle_single_key(self, e):
|
||||||
"""Handle a new keypress with a single key (no modifiers).
|
"""Handle a new keypress with a single key (no modifiers).
|
||||||
|
|
||||||
@ -152,11 +167,13 @@ class BaseKeyParser(QObject):
|
|||||||
txt = e.text()
|
txt = e.text()
|
||||||
key = e.key()
|
key = e.key()
|
||||||
logging.debug("Got key: {} / text: '{}'".format(key, txt))
|
logging.debug("Got key: {} / text: '{}'".format(key, txt))
|
||||||
|
|
||||||
if key == Qt.Key_Escape:
|
if key == Qt.Key_Escape:
|
||||||
logging.debug("Escape pressed, discarding '{}'.".format(
|
logging.debug("Escape pressed, discarding '{}'.".format(
|
||||||
self._keystring))
|
self._keystring))
|
||||||
self._keystring = ''
|
self._keystring = ''
|
||||||
return
|
return
|
||||||
|
|
||||||
if txt not in (string.ascii_letters + string.digits +
|
if txt not in (string.ascii_letters + string.digits +
|
||||||
string.punctuation):
|
string.punctuation):
|
||||||
logging.debug("Ignoring, no text char")
|
logging.debug("Ignoring, no text char")
|
||||||
@ -165,19 +182,13 @@ class BaseKeyParser(QObject):
|
|||||||
self._stop_delayed_exec()
|
self._stop_delayed_exec()
|
||||||
self._keystring += txt
|
self._keystring += txt
|
||||||
|
|
||||||
if self._supports_count:
|
count, cmd_input = self._split_count()
|
||||||
(countstr, cmd_input) = re.match(r'^(\d*)(.*)',
|
|
||||||
self._keystring).groups()
|
|
||||||
count = int(countstr) if countstr else None
|
|
||||||
else:
|
|
||||||
cmd_input = self._keystring
|
|
||||||
count = None
|
|
||||||
|
|
||||||
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 True
|
||||||
|
|
||||||
(match, binding) = self._match_key(cmd_input)
|
match, binding = self._match_key(cmd_input)
|
||||||
|
|
||||||
if match == self.Match.definitive:
|
if match == self.Match.definitive:
|
||||||
logging.debug("Definitive match for "
|
logging.debug("Definitive match for "
|
||||||
|
Loading…
Reference in New Issue
Block a user