From 469a52846b4c8aa4c4319a2d41d0a8651e30d077 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Sun, 13 Oct 2024 13:55:38 +0900 Subject: [PATCH] Support continuous tab completion (#761) Continuous tab completion is possible in GNU Readline. If dig_perfect_match_proc is set, continuous tab completion will be disabled. --- lib/reline/line_editor.rb | 6 +++++- test/reline/test_key_actor_emacs.rb | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index e01d859262..f6627ca430 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -846,7 +846,11 @@ def editing_mode when CompletionState::NORMAL @completion_state = CompletionState::COMPLETION when CompletionState::PERFECT_MATCH - @dig_perfect_match_proc&.(@perfect_matched) + if @dig_perfect_match_proc + @dig_perfect_match_proc.(@perfect_matched) + else + @completion_state = CompletionState::COMPLETION + end end if just_show_list is_menu = true diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index cd8971298d..2ebd91dc2e 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -920,6 +920,29 @@ def test_completion_with_perfect_match assert_equal('foo_bar', matched) end + def test_continuous_completion_with_perfect_match + @line_editor.completion_proc = proc { |word| + word == 'f' ? ['foo'] : %w[foobar foobaz] + } + input_keys('f') + input_keys("\C-i", false) + assert_line_around_cursor('foo', '') + input_keys("\C-i", false) + assert_line_around_cursor('fooba', '') + end + + def test_continuous_completion_disabled_with_perfect_match + @line_editor.completion_proc = proc { |word| + word == 'f' ? ['foo'] : %w[foobar foobaz] + } + @line_editor.dig_perfect_match_proc = proc {} + input_keys('f') + input_keys("\C-i", false) + assert_line_around_cursor('foo', '') + input_keys("\C-i", false) + assert_line_around_cursor('foo', '') + end + def test_completion_with_completion_ignore_case @line_editor.completion_proc = proc { |word| %w{