Support !-keysections, don't bind leave-mode in normal mode.

This commit is contained in:
Florian Bruhin 2014-09-12 07:33:52 +02:00
parent e516589fe3
commit a796482c83
2 changed files with 21 additions and 3 deletions

View File

@ -797,6 +797,10 @@ KEY_FIRST_COMMENT = """
# All blank lines and lines starting with '#' are ignored.
# Inline-comments are not permitted.
#
# keymode is a comma separated list of modes in which the keybinding should be
# active. If keymode starts with !, the keybinding is active in all modes
# except the listed modes.
#
# For special keys (can't be part of a keychain), enclose them in `<`...`>`.
# For modifiers, you can use either `-` or `+` as delimiters, and these names:
#
@ -854,7 +858,7 @@ KEY_SECTION_DESC = {
KEY_DATA = collections.OrderedDict([
('all', collections.OrderedDict([
('!normal', collections.OrderedDict([
('leave-mode', ['<Escape>', '<Ctrl-[>']),
])),

View File

@ -175,7 +175,15 @@ class KeyConfigParser(QObject):
def _normalize_sectname(self, s):
"""Normalize a section string like 'foo, bar,baz' to 'bar,baz,foo'."""
return ','.join(sorted(s.split(',')))
if s.startswith('!'):
inverted = True
s = s[1:]
else:
inverted = False
sections = ','.join(sorted(s.split(',')))
if inverted:
sections = '!' + sections
return sections
def _load_default(self):
"""Load the built-in default keybindings."""
@ -246,8 +254,14 @@ class KeyConfigParser(QObject):
"""Get a dict with all merged keybindings for a section."""
bindings = {}
for sectstring, d in self.keybindings.items():
if sectstring.startswith('!'):
inverted = True
sectstring = sectstring[1:]
else:
inverted = False
sects = [s.strip() for s in sectstring.split(',')]
if any(s == section for s in sects):
matches = any(s == section for s in sects)
if (not inverted and matches) or (inverted and not matches):
bindings.update(d)
try:
bindings.update(self.keybindings['all'])