Fix remaining :bind/:unbind issues
This commit is contained in:
parent
f434f955c2
commit
23d30d4fc0
@ -143,8 +143,7 @@ class NewKeyConfig:
|
||||
def _prepare(self, key, mode):
|
||||
"""Make sure the given mode exists and normalize the key."""
|
||||
if mode not in val.bindings.commands:
|
||||
raise configexc.KeybindingError(
|
||||
"Invalid mode {} while binding {}!".format(mode, key))
|
||||
raise configexc.KeybindingError("Invalid mode {}!".format(mode))
|
||||
if utils.is_special_key(key):
|
||||
# <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
|
||||
return utils.normalize_keystr(key)
|
||||
@ -158,14 +157,12 @@ class NewKeyConfig:
|
||||
try:
|
||||
results = parser.parse_all(command)
|
||||
except cmdexc.Error as e:
|
||||
# FIXME: conf good message?
|
||||
raise configexc.KeybindingError("Invalid command: {}".format(e))
|
||||
|
||||
for result in results:
|
||||
try:
|
||||
result.cmd.validate_mode(usertypes.KeyMode[mode])
|
||||
except cmdexc.PrerequisitesError as e:
|
||||
# FIXME: conf good message?
|
||||
raise configexc.KeybindingError(str(e))
|
||||
|
||||
bindings = val.bindings.commands
|
||||
@ -180,11 +177,13 @@ class NewKeyConfig:
|
||||
def unbind(self, key, *, mode='normal'):
|
||||
"""Unbind the given key in the given mode."""
|
||||
key = self._prepare(key, mode)
|
||||
bindings = val.bindings.commands
|
||||
try:
|
||||
del val.bindings.commands[mode][key]
|
||||
del bindings[mode][key]
|
||||
except KeyError:
|
||||
raise configexc.KeybindingError("Unknown binding {}".format(key))
|
||||
val.bindings.commands = val.bindings.commands # FIXME:conf
|
||||
raise configexc.KeybindingError("Can't find binding '{}' in section '{}'!"
|
||||
.format(key, mode))
|
||||
val.bindings.commands = bindings # FIXME:conf
|
||||
|
||||
def get_command(self, key, mode):
|
||||
"""Get the command for a given key (or None)."""
|
||||
|
@ -14,7 +14,7 @@ Feature: Keyboard input
|
||||
|
||||
Scenario: Binding an invalid command
|
||||
When I run :bind test02 abcd
|
||||
Then the error "Invalid command 'abcd'!" should be shown
|
||||
Then the error "abcd: no such command" should be shown
|
||||
|
||||
Scenario: Binding with invalid mode.
|
||||
When I run :bind --mode abcd test03 message-info test03
|
||||
@ -24,7 +24,7 @@ Feature: Keyboard input
|
||||
When I run :bind test04 message-info test04
|
||||
And I run :bind test04 message-info test04-2
|
||||
And I press the keys "test04"
|
||||
Then the error "Duplicate keychain test04 - use --force to override!" should be shown
|
||||
Then the error "Duplicate key test04 - use --force to override!" should be shown
|
||||
And the message "test04" should be shown
|
||||
|
||||
Scenario: Double-binding with --force
|
||||
@ -50,30 +50,32 @@ Feature: Keyboard input
|
||||
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
|
||||
Then the error "Duplicate key <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
|
||||
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
|
||||
Then the message "<ctrl+test23> is bound to 'message-info bar' in normal mode" should be shown
|
||||
|
||||
Scenario: Binding to an alias
|
||||
When I run :set aliases 'mib' 'message-info baz'
|
||||
And I run :bind test25 mib
|
||||
And I press the keys "test25"
|
||||
Then the message "baz" should be shown
|
||||
## FIXME:conf
|
||||
|
||||
Scenario: Printing a bound alias
|
||||
When I run :set aliases 'mib' 'message-info baz'
|
||||
And I run :bind <test26> mib
|
||||
And I run :bind <test26>
|
||||
Then the message "<test26> is bound to 'mib' in normal mode" should be shown
|
||||
# Scenario: Binding to an alias
|
||||
# When I run :set aliases 'mib' 'message-info baz'
|
||||
# And I run :bind test25 mib
|
||||
# And I press the keys "test25"
|
||||
# Then the message "baz" should be shown
|
||||
|
||||
# Scenario: Printing a bound alias
|
||||
# When I run :set aliases 'mib' 'message-info baz'
|
||||
# And I run :bind <test26> mib
|
||||
# And I run :bind <test26>
|
||||
# Then the message "<test26> is bound to 'mib' in normal mode" should be shown
|
||||
|
||||
Scenario: Binding with an unsupported mode
|
||||
When I run :bind --mode=caret test27 rl-unix-filename-rubout
|
||||
@ -83,7 +85,9 @@ Feature: Keyboard input
|
||||
|
||||
Scenario: Binding and unbinding a keychain
|
||||
When I run :bind test09 message-error test09
|
||||
And I wait for "Config option changed: *" in the log
|
||||
And I run :unbind test09
|
||||
And I wait for "Config option changed: *" in the log
|
||||
And I press the keys "test09"
|
||||
Then "test09" should not be logged
|
||||
|
||||
@ -105,7 +109,7 @@ Feature: Keyboard input
|
||||
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
|
||||
Then the message "<ctrl+test24> is unbound in normal mode" should be shown
|
||||
|
||||
# :clear-keychain
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user