Add a setting to clear all shortcuts defined up to that point

This commit is contained in:
Kovid Goyal 2018-04-24 09:08:22 +05:30
parent bd0382830a
commit f5abe7cbf7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 19 additions and 6 deletions

View File

@ -333,6 +333,7 @@ type_map = {
'copy_on_select': to_bool, 'copy_on_select': to_bool,
'tab_bar_edge': tab_bar_edge, 'tab_bar_edge': tab_bar_edge,
'kitty_mod': to_modifiers, 'kitty_mod': to_modifiers,
'clear_all_shortcuts': to_bool,
} }
for name in ( for name in (
@ -347,6 +348,11 @@ for a in ('active', 'inactive'):
type_map['%s_tab_%s' % (a, b)] = to_color type_map['%s_tab_%s' % (a, b)] = to_color
def init_shortcut_maps(ans):
ans['keymap'] = {}
ans['sequence_map'] = {}
def special_handling(key, val, ans): def special_handling(key, val, ans):
if key == 'map': if key == 'map':
parse_key(val, ans['keymap'], ans['sequence_map']) parse_key(val, ans['keymap'], ans['sequence_map'])
@ -358,6 +364,10 @@ def special_handling(key, val, ans):
# For legacy compatibility # For legacy compatibility
parse_send_text(val, ans['keymap'], ans['sequence_map']) parse_send_text(val, ans['keymap'], ans['sequence_map'])
return True return True
if key == 'clear_all_shortcuts':
if to_bool(val):
init_shortcut_maps(ans)
return
defaults = None defaults = None
@ -367,11 +377,8 @@ default_config_path = os.path.join(
def parse_config(lines, check_keys=True): def parse_config(lines, check_keys=True):
ans = { ans = {'symbol_map': {}}
'keymap': {}, init_shortcut_maps(ans)
'sequence_map': {},
'symbol_map': {},
}
parse_config_base( parse_config_base(
lines, lines,
defaults, defaults,
@ -436,9 +443,12 @@ def merge_configs(defaults, vals):
ans[k] = merge_dicts(v, newvals) ans[k] = merge_dicts(v, newvals)
else: else:
ans[k] = vals.get(k, v) ans[k] = vals.get(k, v)
defvals = {'keymap': defaults.get('keymap', {}), 'sequence_map': defaults.get('sequence_map', {})}
if vals.get('clear_all_shortcuts'):
init_shortcut_maps(defvals)
merge_keys( merge_keys(
ans, ans,
{'keymap': defaults.get('keymap', {}), 'sequence_map': defaults.get('sequence_map', {})}, defvals,
{'keymap': vals.get('keymap', {}), 'sequence_map': vals.get('sequence_map', {})} {'keymap': vals.get('keymap', {}), 'sequence_map': vals.get('sequence_map', {})}
) )
return ans return ans

View File

@ -485,6 +485,9 @@ map kitty_mod+escape kitty_shell window
# map ctrl+alt+a send_text application Word\x1bOH # map ctrl+alt+a send_text application Word\x1bOH
# }}} # }}}
# You can have kitty remove all shortcut definition seen upto this point. Useful for
# instance, to remove the default shortcuts.
clear_all_shortcuts no
# }}} # }}}