More key refactoring

This commit is contained in:
Florian Bruhin 2014-01-19 20:45:01 +01:00
parent a6aa95cba8
commit bf99519046
2 changed files with 19 additions and 10 deletions

View File

@ -8,7 +8,7 @@ class Open(Command):
class TabOpen(Command):
nargs = 1
key = 'Shift+o'
key = 'O'
signal = pyqtSignal(str)
class TabClose(Command):
@ -18,12 +18,12 @@ class TabClose(Command):
class TabNext(Command):
nargs = 0
key = 'Shift+j'
key = 'J'
signal = pyqtSignal()
class TabPrev(Command):
nargs = 0
key = 'Shift+k'
key = 'K'
signal = pyqtSignal()
class Quit(Command):
@ -41,12 +41,12 @@ class Stop(Command):
class Back(Command):
nargs = 0
key = 'Shift+H'
key = 'H'
signal = pyqtSignal()
class Forward(Command):
nargs = 0
key = 'Shift+L'
key = 'L'
signal = pyqtSignal()
class Print(Command):
@ -84,10 +84,10 @@ class Undo(Command):
class ScrollStart(Command):
nargs = 0
key = 'g, g'
key = 'gg'
signal = pyqtSignal()
class ScrollEnd(Command):
nargs = 0
key = 'Shift+g'
key = 'G'
signal = pyqtSignal()

View File

@ -15,7 +15,10 @@ class KeyParser(QObject):
self.key_to_cmd[cmd.key] = cmd
def handle(self, e):
logging.debug('Got key: {} / text: {}'.format(e.key(), e.text()))
logging.debug('Got key: {} / text: "{}"'.format(e.key(), e.text()))
if not e.text().strip():
logging.debug('Ignoring, no text')
return
self.keystring += e.text()
if self.keystring == ':':
self.set_cmd_text.emit(':')
@ -24,11 +27,17 @@ class KeyParser(QObject):
try:
cmd = self.key_to_cmd[self.keystring]
except KeyError:
pos = len(self.keystring)
if any([self.keystring[-1] == needle[pos-1]
for needle in self.key_to_cmd]):
logging.debug('No match for "{}" (added {})'.format(self.keystring, e.text()))
pass
else:
logging.debug('Giving up with "{}", no matches'.format(self.keystring))
self.keystring = ''
else:
self.keystring = ''
if cmd.nargs and cmd.nargs != 0:
logging.debug('Filling statusbar with partial command {}'.format(cmd.name))
self.set_cmd_text.emit(':{} '.format(cmd.name))
else:
cmd.run()