Skip to content

Commit 469a528

Browse files
authored
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.
1 parent 2f21d1e commit 469a528

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/reline/line_editor.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,11 @@ def editing_mode
846846
when CompletionState::NORMAL
847847
@completion_state = CompletionState::COMPLETION
848848
when CompletionState::PERFECT_MATCH
849-
@dig_perfect_match_proc&.(@perfect_matched)
849+
if @dig_perfect_match_proc
850+
@dig_perfect_match_proc.(@perfect_matched)
851+
else
852+
@completion_state = CompletionState::COMPLETION
853+
end
850854
end
851855
if just_show_list
852856
is_menu = true

test/reline/test_key_actor_emacs.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,29 @@ def test_completion_with_perfect_match
920920
assert_equal('foo_bar', matched)
921921
end
922922

923+
def test_continuous_completion_with_perfect_match
924+
@line_editor.completion_proc = proc { |word|
925+
word == 'f' ? ['foo'] : %w[foobar foobaz]
926+
}
927+
input_keys('f')
928+
input_keys("\C-i", false)
929+
assert_line_around_cursor('foo', '')
930+
input_keys("\C-i", false)
931+
assert_line_around_cursor('fooba', '')
932+
end
933+
934+
def test_continuous_completion_disabled_with_perfect_match
935+
@line_editor.completion_proc = proc { |word|
936+
word == 'f' ? ['foo'] : %w[foobar foobaz]
937+
}
938+
@line_editor.dig_perfect_match_proc = proc {}
939+
input_keys('f')
940+
input_keys("\C-i", false)
941+
assert_line_around_cursor('foo', '')
942+
input_keys("\C-i", false)
943+
assert_line_around_cursor('foo', '')
944+
end
945+
923946
def test_completion_with_completion_ignore_case
924947
@line_editor.completion_proc = proc { |word|
925948
%w{

0 commit comments

Comments
 (0)