Change CHANGED_KEY_COMMANDS to be regexes.

Break after first regex
This commit is contained in:
Florian Bruhin 2015-04-03 16:12:33 +02:00
parent a504bd1436
commit 630a827afc
2 changed files with 13 additions and 10 deletions

View File

@ -1181,13 +1181,12 @@ KEY_DATA = collections.OrderedDict([
]) ])
# A dict of {old_cmd: new_cmd} strings. # A list of (regex, replacement) tuples of changed key commands.
CHANGED_KEY_COMMNADS = { CHANGED_KEY_COMMANDS = [
'open -t about:blank': 'open -t', (re.compile(r'^open -([twb]) about:blank$'), r'open -\1'),
'open -b about:blank': 'open -b', (re.compile(r'^download-page$'), r'download'),
'open -w about:blank': 'open -w', (re.compile(r'^cancel-download$'), r'download-cancel'),
'download-page': 'download', (re.compile(r'^search ""$'), r'search'),
'cancel-download': 'download-cancel', (re.compile(r"^search ''$"), r'search'),
'search ""': 'search', ]
}

View File

@ -255,7 +255,11 @@ class KeyConfigParser(QObject):
command = line.split(maxsplit=1)[0] command = line.split(maxsplit=1)[0]
if command not in cmdutils.cmd_dict: if command not in cmdutils.cmd_dict:
raise KeyConfigError("Invalid command '{}'!".format(command)) raise KeyConfigError("Invalid command '{}'!".format(command))
self._cur_command = configdata.CHANGED_KEY_COMMNADS.get(line, line) for rgx, repl in configdata.CHANGED_KEY_COMMANDS:
if rgx.match(line):
line = rgx.sub(repl, line)
break
self._cur_command = line
def _read_keybinding(self, line): def _read_keybinding(self, line):
"""Read a key binding from a line.""" """Read a key binding from a line."""