summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2024-10-13 13:55:38 +0900
committergit <[email protected]>2024-10-13 04:55:41 +0000
commit98fce00cab460be81cb1f5e4cf8c0d66e006a35b (patch)
tree63dab310e8cc3b0b19483d20701b7a845530b52a
parentc12c95462a22551af2f0437cd08136b55c4bb4b7 (diff)
[ruby/reline] Support continuous tab completion
(https://github.com/ruby/reline/pull/761) Continuous tab completion is possible in GNU Readline. If dig_perfect_match_proc is set, continuous tab completion will be disabled. https://github.com/ruby/reline/commit/469a52846b
-rw-r--r--lib/reline/line_editor.rb6
-rw-r--r--test/reline/test_key_actor_emacs.rb23
2 files changed, 28 insertions, 1 deletions
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 @@ class Reline::LineEditor
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 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase
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{