From 646ad5efd4bb2a7dc4df40ccf972be12c9207cbb Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 20 Jan 2014 09:09:57 +0100 Subject: [PATCH] Refactor partial matching in KeyParser._handle() --- qutebrowser/commands/keys.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/qutebrowser/commands/keys.py b/qutebrowser/commands/keys.py index 7c27c3a4b..289d41e7f 100644 --- a/qutebrowser/commands/keys.py +++ b/qutebrowser/commands/keys.py @@ -47,10 +47,7 @@ class KeyParser(QObject): try: cmd = self.key_to_cmd[cmdstr] except KeyError: - pos = len(cmdstr) - # FIXME we get an IndexError here sometimes (e.g. with 'go') - if any([cmdstr[-1] == needle[pos-1] - for needle in self.key_to_cmd]): + if self._partial_match(cmdstr, txt): logging.debug('No match for "{}" (added {})'.format( self.keystring, txt)) return @@ -71,3 +68,14 @@ class KeyParser(QObject): cmd.run(count=count) else: cmd.run() + + def _partial_match(self, cmdstr, txt): + pos = len(cmdstr) + for cmd in self.key_to_cmd: + try: + if cmdstr[-1] == cmd[pos-1]: + return True + except IndexError: + continue + else: + return False