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 = {
'open -t about:blank': 'open -t',
'open -b about:blank': 'open -b',
'open -w about:blank': 'open -w',
'download-page': 'download',
'cancel-download': 'download-cancel',
'search ""': 'search',
}
CHANGED_KEY_COMMANDS = [
(re.compile(r'^open -([twb]) about:blank$'), r'open -\1'),
(re.compile(r'^download-page$'), r'download'),
(re.compile(r'^cancel-download$'), r'download-cancel'),
(re.compile(r'^search ""$'), r'search'),
(re.compile(r"^search ''$"), r'search'),
]

View File

@ -255,7 +255,11 @@ class KeyConfigParser(QObject):
command = line.split(maxsplit=1)[0]
if command not in cmdutils.cmd_dict:
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):
"""Read a key binding from a line."""