Support disable-completion
This commit is contained in:
parent
ad8fbf444a
commit
e3587ed849
@ -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)
|
||||
|
@ -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('')
|
||||
|
Loading…
x
Reference in New Issue
Block a user