diff options
author | aycabta <aycabta@gmail.com> | 2019-12-04 22:32:12 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-12-05 09:02:23 +0900 |
commit | e3587ed8498dcf7a3a8178030f7ae66cd0719c57 (patch) | |
tree | 48b30d4fb3a2cc17c6f4070f9b381441fdfc0dc1 | |
parent | ad8fbf444abdf1480d87c95b2868741f98eb953f (diff) | |
download | ruby-e3587ed8498dcf7a3a8178030f7ae66cd0719c57.tar.gz |
Support disable-completion
-rw-r--r-- | lib/reline/line_editor.rb | 30 | ||||
-rw-r--r-- | test/reline/test_key_actor_vi.rb | 39 |
2 files changed, 56 insertions, 13 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 072238f8a8..f029aa4e6e 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -776,20 +776,24 @@ class Reline::LineEditor @first_char = false completion_occurs = false if @config.editing_mode_is?(:emacs, :vi_insert) and key.char == "\C-i".ord - result = retrieve_completion_block - slice = result[1] - result = @completion_proc.(slice) if @completion_proc and slice - if result.is_a?(Array) - completion_occurs = true - complete(result) + unless @config.disable_completion + result = retrieve_completion_block + slice = result[1] + result = @completion_proc.(slice) if @completion_proc and slice + if result.is_a?(Array) + completion_occurs = true + complete(result) + end end - elsif @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char) - result = retrieve_completion_block - slice = result[1] - result = @completion_proc.(slice) if @completion_proc and slice - if result.is_a?(Array) - completion_occurs = true - move_completed_list(result, "\C-p".ord == key.char ? :up : :down) + elsif not @config.disable_completion and @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char) + unless @config.disable_completion + result = retrieve_completion_block + slice = result[1] + result = @completion_proc.(slice) if @completion_proc and slice + if result.is_a?(Array) + completion_occurs = true + move_completed_list(result, "\C-p".ord == key.char ? :up : :down) + end end elsif Symbol === key.char and respond_to?(key.char, true) process_key(key.char, key.char) diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index 52362e5893..be55a10e77 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -988,6 +988,45 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase assert_line('abcde foo_bar_baz ABCDE') end + def test_completion + @line_editor.completion_proc = proc { |word| + %w{ + foo_bar + foo_bar_baz + } + } + input_keys('foo') + assert_byte_pointer_size('foo') + assert_cursor(3) + assert_cursor_max(3) + assert_line('foo') + input_keys("\C-i") + assert_byte_pointer_size('foo_bar') + assert_cursor(7) + assert_cursor_max(7) + assert_line('foo_bar') + end + + def test_completion_with_disable_completion + @config.disable_completion = true + @line_editor.completion_proc = proc { |word| + %w{ + foo_bar + foo_bar_baz + } + } + input_keys('foo') + assert_byte_pointer_size('foo') + assert_cursor(3) + assert_cursor_max(3) + assert_line('foo') + input_keys("\C-i") + assert_byte_pointer_size('foo') + assert_cursor(3) + assert_cursor_max(3) + assert_line('foo') + end + def test_vi_first_print input_keys("abcde\C-[^") assert_byte_pointer_size('') |