Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor and fix keybinding issue (fixes #447)
This changes the logic for the function get_key_no_doublebind() and removes the mutable list which was previously used to keep track of keybindings which were already used. Although this fix passes the test cases and the specific case mentioned in #447, the behavior is such that specifying the same custom keybinding for two commands will result in only one command being bound.
  • Loading branch information
keyan committed Jan 21, 2015
commit 51dbf41437366d4ae6719c43315a31eaf8d389b9
55 changes: 44 additions & 11 deletions bpython/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ def loadini(struct, configfile):
'list_above' : False,
'right_arrow_completion' : True,
}}

default_keys_to_commands = {
'': 'exit',
'C-n': 'down_one_line',
'C-l': 'clear_screen',
'C-k': 'kill_line',
'C-o': 'search',
'C-h': 'backspace',
'C-f': 'right',
'C-e': 'end_of_line',
'C-d': 'delete',
'C-b':'left',
'C-a': 'beginning_of_line',
'C-z': 'suspend',
'C-y': 'yank_from_buffer',
'C-x': 'edit_current_block',
'C-w': 'clear_word',
'C-u': 'clear_line',
'C-t': 'transpose_chars',
'C-s': 'save',
'C-r': 'undo',
'C-p': 'up_one_line',
'F10': 'copy_clipboard',
'F1': 'help',
'F2': 'show_source',
'F3': 'edit_config',
'F5': 'toggle_file_watch',
'F6': 'reimport',
'F7': 'external_editor',
'F8': 'pastebin',
'F9': 'last_output'
}

fill_config_with_default_values(config, defaults)
if not config.read(config_path):
# No config file. If the user has it in the old place then complain
Expand All @@ -113,17 +146,17 @@ def loadini(struct, configfile):
"%s\n" % default_config_path())
sys.exit(1)

def get_key_no_doublebind(attr, already_used={}):
"""Clears any other configured keybindings using this key"""
key = config.get('keyboard', attr)
if key in already_used:
default = defaults['keyboard'][already_used[key]]
if default in already_used:
setattr(struct, '%s_key' % already_used[key], '')
else:
setattr(struct, '%s_key' % already_used[key], default)
already_used[key] = attr
return key

def get_key_no_doublebind(command):
default_commands_to_keys = defaults['keyboard']
requested_key = config.get('keyboard', command)
default_command = default_keys_to_commands[requested_key]

if default_commands_to_keys[default_command] == \
config.get('keyboard', default_command):
setattr(struct, '%s_key' % default_command, '')

return requested_key

struct.config_path = config_path

Expand Down