aboutsummaryrefslogtreecommitdiffstats
path: root/lib/reline/config.rb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-04-05 16:03:53 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-04-08 21:41:00 +0900
commit5543695a19faccea325f91c9791d06dc4d29e132 (patch)
tree15d58fc8f8a9e0daac8d7d2c75cfd47d3a4aae65 /lib/reline/config.rb
parent16f31da92e0c8722cb1f708d1a6938c386d477cf (diff)
downloadruby-5543695a19faccea325f91c9791d06dc4d29e132.tar.gz
[ruby/reline] Separate keystrokes each editing mode
https://github.com/ruby/reline/commit/ee23e6f3f8
Diffstat (limited to 'lib/reline/config.rb')
-rw-r--r--lib/reline/config.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 63ab7b7402..f916fc63ff 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -47,7 +47,9 @@ class Reline::Config
def initialize
@additional_key_bindings = {} # from inputrc
- @default_key_bindings = {} # environment-dependent
+ @additional_key_bindings[:emacs] = {}
+ @additional_key_bindings[:vi_insert] = {}
+ @additional_key_bindings[:vi_command] = {}
@skip_section = nil
@if_stack = nil
@editing_mode_label = :emacs
@@ -69,8 +71,9 @@ class Reline::Config
if editing_mode_is?(:vi_command)
@editing_mode_label = :vi_insert
end
- @additional_key_bindings = {}
- @default_key_bindings = {}
+ @additional_key_bindings.keys.each do |key|
+ @additional_key_bindings[key].clear
+ end
end
def editing_mode
@@ -135,16 +138,22 @@ class Reline::Config
end
def key_bindings
- # override @default_key_bindings with @additional_key_bindings
- @default_key_bindings.merge(@additional_key_bindings)
+ # override @key_actors[@editing_mode_label].default_key_bindings with @additional_key_bindings[@editing_mode_label]
+ @key_actors[@editing_mode_label].default_key_bindings.merge(@additional_key_bindings[@editing_mode_label])
+ end
+
+ def add_default_key_binding_by_keymap(keymap, keystroke, target)
+ @key_actors[keymap].default_key_bindings[keystroke] = target
end
def add_default_key_binding(keystroke, target)
- @default_key_bindings[keystroke] = target
+ @key_actors[@keymap_label].default_key_bindings[keystroke] = target
end
def reset_default_key_bindings
- @default_key_bindings = {}
+ @key_actors.values.each do |ka|
+ ka.reset_default_key_bindings
+ end
end
def read_lines(lines, file = nil)
@@ -174,7 +183,7 @@ class Reline::Config
key, func_name = $1, $2
keystroke, func = bind_key(key, func_name)
next unless keystroke
- @additional_key_bindings[keystroke] = func
+ @additional_key_bindings[@keymap_label][keystroke] = func
end
end
unless @if_stack.empty?