Skip to content

Commit

Permalink
Support continuous tab completion (#761)
Browse files Browse the repository at this point in the history
Continuous tab completion is possible in GNU Readline.
If dig_perfect_match_proc is set, continuous tab completion will be disabled.
  • Loading branch information
tompng authored Oct 13, 2024
1 parent 2f21d1e commit 469a528
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 469a528

Please sign in to comment.