Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default and additional key bindings vanish bug #697

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ def readline(prompt = '', add_hist = false)

unless config.test_mode or config.loaded?
config.read
config.reset_default_key_bindings
io_gate.set_default_key_bindings(config)
end

Expand Down
12 changes: 1 addition & 11 deletions lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ def reset
if editing_mode_is?(:vi_command)
@editing_mode_label = :vi_insert
end
@additional_key_bindings.keys.each do |key|
@additional_key_bindings[key].clear
end
@oneshot_key_bindings.clear
reset_default_key_bindings
end

def editing_mode
Expand Down Expand Up @@ -134,6 +130,7 @@ def inputrc_path
end

def read(file = nil)
@loaded = true
file ||= default_inputrc_path
begin
if file.respond_to?(:readlines)
Expand All @@ -146,7 +143,6 @@ def read(file = nil)
end

read_lines(lines, file)
@loaded = true
self
rescue InvalidInputrc => e
warn e.message
Expand Down Expand Up @@ -177,12 +173,6 @@ def add_default_key_binding(keystroke, target)
@key_actors[@keymap_label].default_key_bindings[keystroke] = target
end

def reset_default_key_bindings
@key_actors.values.each do |ka|
ka.reset_default_key_bindings
end
end

def read_lines(lines, file = nil)
if not lines.empty? and lines.first.encoding != Reline.encoding_system_needs
begin
Expand Down
4 changes: 0 additions & 4 deletions lib/reline/key_actor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ def initialize
def default_key_bindings
@default_key_bindings
end

def reset_default_key_bindings
@default_key_bindings.clear
end
end
12 changes: 12 additions & 0 deletions test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ def test_additional_key_bindings_for_auxiliary_emacs_keymaps
assert_equal expected, @config.key_bindings
end

def test_key_bindings_with_reset
# @config.reset is called after each readline.
# inputrc file is read once, so key binding shouldn't be cleared by @config.reset
@config.add_default_key_binding('default'.bytes, 'DEFAULT'.bytes)
@config.read_lines(<<~'LINES'.lines)
"additional": "ADDITIONAL"
LINES
@config.reset
expected = { 'default'.bytes => 'DEFAULT'.bytes, 'additional'.bytes => 'ADDITIONAL'.bytes }
assert_equal expected, @config.key_bindings
end

def test_history_size
@config.read_lines(<<~LINES.lines)
set history-size 5000
Expand Down
1 change: 0 additions & 1 deletion test/reline/test_within_pipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def teardown
@reader.close
@output_writer.close
@config.reset
@config.reset_default_key_bindings
Reline.test_reset
end

Expand Down
Loading