Merge branch 'bind_case_fix' of https://github.com/rcorre/qutebrowser into rcorre-bind_case_fix

This commit is contained in:
Florian Bruhin 2016-06-04 23:30:50 +02:00
commit 9f3c2dfada
2 changed files with 34 additions and 6 deletions

View File

@ -154,7 +154,7 @@ class KeyConfigParser(QObject):
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
@cmdutils.argument('key', completion=usertypes.Completion.empty) @cmdutils.argument('key', completion=usertypes.Completion.empty)
@cmdutils.argument('command', completion=usertypes.Completion.command) @cmdutils.argument('command', completion=usertypes.Completion.command)
def bind(self, key, win_id, command=None, *, mode=None, force=False): def bind(self, key, win_id, command=None, *, mode='normal', force=False):
"""Bind a key to a command. """Bind a key to a command.
Args: Args:
@ -165,8 +165,9 @@ class KeyConfigParser(QObject):
(default: `normal`). (default: `normal`).
force: Rebind the key if it is already bound. force: Rebind the key if it is already bound.
""" """
if mode is None: if utils.is_special_key(key):
mode = 'normal' # <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
key = key.lower()
if command is None: if command is None:
cmd = self.get_bindings_for(mode).get(key, None) cmd = self.get_bindings_for(mode).get(key, None)
@ -198,7 +199,7 @@ class KeyConfigParser(QObject):
self._mark_config_dirty() self._mark_config_dirty()
@cmdutils.register(instance='key-config') @cmdutils.register(instance='key-config')
def unbind(self, key, mode=None): def unbind(self, key, mode='normal'):
"""Unbind a keychain. """Unbind a keychain.
Args: Args:
@ -206,8 +207,10 @@ class KeyConfigParser(QObject):
mode: A comma-separated list of modes to unbind the key in mode: A comma-separated list of modes to unbind the key in
(default: `normal`). (default: `normal`).
""" """
if mode is None: if utils.is_special_key(key):
mode = 'normal' # <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
key = key.lower()
mode = self._normalize_sectname(mode) mode = self._normalize_sectname(mode)
for m in mode.split(','): for m in mode.split(','):
if m not in configdata.KEY_DATA: if m not in configdata.KEY_DATA:
@ -377,6 +380,9 @@ class KeyConfigParser(QObject):
def _add_binding(self, sectname, keychain, command, *, force=False): def _add_binding(self, sectname, keychain, command, *, force=False):
"""Add a new binding from keychain to command in section sectname.""" """Add a new binding from keychain to command in section sectname."""
if utils.is_special_key(keychain):
# <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
keychain = keychain.lower()
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format( log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
keychain, command, sectname)) keychain, command, sectname))
if sectname not in self.keybindings: if sectname not in self.keybindings:

View File

@ -45,6 +45,22 @@ Feature: Keyboard input
And I run :bind --mode=caret test08 And I run :bind --mode=caret test08
Then the message "test08 is bound to 'message-info bar' in caret mode" should be shown Then the message "test08 is bound to 'message-info bar' in caret mode" should be shown
Scenario: Binding special keys with differing case (issue 1544)
When I run :bind <ctrl-test21> message-info test01
And I run :bind <Ctrl-Test21> message-info test01
Then the error "Duplicate keychain <ctrl-test21> - use --force to override!" should be shown
Scenario: Print a special binding with differing case (issue 1544)
When I run :bind <Ctrl-Test22> message-info foo
And I run :bind <ctrl-test22>
Then the message "<ctrl-test22> is bound to 'message-info foo' in normal mode" should be shown
Scenario: Overriding a special binding with differing case (issue 816)
When I run :bind <ctrl-test23> message-info foo
And I run :bind --force <Ctrl-Test23> message-info bar
And I run :bind <ctrl-test23>
Then the message "<ctrl-test23> is bound to 'message-info bar' in normal mode" should be shown
# :unbind # :unbind
Scenario: Binding and unbinding a keychain Scenario: Binding and unbinding a keychain
@ -67,6 +83,12 @@ Feature: Keyboard input
Then "No binding found for o." should be logged Then "No binding found for o." should be logged
# maybe check it's unbound in the config? # maybe check it's unbound in the config?
Scenario: Binding and unbinding a special keychain with differing case (issue 1544)
When I run :bind <ctrl-test24> message-error test09
And I run :unbind <Ctrl-Test24>
When I run :bind <ctrl-test24>
Then the message "<ctrl-test24> is unbound in normal mode" should be shown
# :clear-keychain # :clear-keychain
Scenario: Clearing the keychain Scenario: Clearing the keychain