[ruby/reline] Add name defined in readline to completion key
bindings C-i C-p C-n (https://github.com/ruby/reline/pull/698) https://github.com/ruby/reline/commit/1314787bbb
This commit is contained in:
parent
b181ba7400
commit
d679afe9f9
@ -19,7 +19,7 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
|
||||
# 8 ^H
|
||||
:em_delete_prev_char,
|
||||
# 9 ^I
|
||||
:ed_unassigned,
|
||||
:complete,
|
||||
# 10 ^J
|
||||
:ed_newline,
|
||||
# 11 ^K
|
||||
|
@ -19,7 +19,7 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base
|
||||
# 8 ^H
|
||||
:vi_delete_prev_char,
|
||||
# 9 ^I
|
||||
:ed_insert,
|
||||
:complete,
|
||||
# 10 ^J
|
||||
:ed_newline,
|
||||
# 11 ^K
|
||||
@ -29,11 +29,11 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base
|
||||
# 13 ^M
|
||||
:ed_newline,
|
||||
# 14 ^N
|
||||
:ed_insert,
|
||||
:menu_complete,
|
||||
# 15 ^O
|
||||
:ed_insert,
|
||||
# 16 ^P
|
||||
:ed_insert,
|
||||
:menu_complete_backward,
|
||||
# 17 ^Q
|
||||
:ed_ignore,
|
||||
# 18 ^R
|
||||
|
@ -235,7 +235,6 @@ class Reline::LineEditor
|
||||
@vi_waiting_operator_arg = nil
|
||||
@completion_journey_state = nil
|
||||
@completion_state = CompletionState::NORMAL
|
||||
@completion_occurs = false
|
||||
@perfect_matched = nil
|
||||
@menu_info = nil
|
||||
@searching_prompt = nil
|
||||
@ -856,7 +855,7 @@ class Reline::LineEditor
|
||||
[target, preposing, completed, postposing]
|
||||
end
|
||||
|
||||
private def complete(list, just_show_list)
|
||||
private def perform_completion(list, just_show_list)
|
||||
case @completion_state
|
||||
when CompletionState::NORMAL
|
||||
@completion_state = CompletionState::COMPLETION
|
||||
@ -885,12 +884,12 @@ class Reline::LineEditor
|
||||
@completion_state = CompletionState::PERFECT_MATCH
|
||||
else
|
||||
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
|
||||
complete(list, true) if @config.show_all_if_ambiguous
|
||||
perform_completion(list, true) if @config.show_all_if_ambiguous
|
||||
end
|
||||
@perfect_matched = completed
|
||||
else
|
||||
@completion_state = CompletionState::MENU
|
||||
complete(list, true) if @config.show_all_if_ambiguous
|
||||
perform_completion(list, true) if @config.show_all_if_ambiguous
|
||||
end
|
||||
if not just_show_list and target < completed
|
||||
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding)
|
||||
@ -1065,10 +1064,6 @@ class Reline::LineEditor
|
||||
end
|
||||
|
||||
private def normal_char(key)
|
||||
if key.combined_char.is_a?(Symbol)
|
||||
process_key(key.combined_char, key.combined_char)
|
||||
return
|
||||
end
|
||||
@multibyte_buffer << key.combined_char
|
||||
if @multibyte_buffer.size > 1
|
||||
if @multibyte_buffer.dup.force_encoding(@encoding).valid_encoding?
|
||||
@ -1128,29 +1123,8 @@ class Reline::LineEditor
|
||||
old_lines = @buffer_of_lines.dup
|
||||
@first_char = false
|
||||
@completion_occurs = false
|
||||
if @config.editing_mode_is?(:emacs, :vi_insert) and key.char == "\C-i".ord
|
||||
if !@config.disable_completion
|
||||
process_insert(force: true)
|
||||
if @config.autocompletion
|
||||
@completion_state = CompletionState::NORMAL
|
||||
@completion_occurs = move_completed_list(:down)
|
||||
else
|
||||
@completion_journey_state = nil
|
||||
result = call_completion_proc
|
||||
if result.is_a?(Array)
|
||||
@completion_occurs = true
|
||||
complete(result, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
elsif @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char)
|
||||
# In vi mode, move completed list even if autocompletion is off
|
||||
if not @config.disable_completion
|
||||
process_insert(force: true)
|
||||
@completion_state = CompletionState::NORMAL
|
||||
@completion_occurs = move_completed_list("\C-p".ord == key.char ? :up : :down)
|
||||
end
|
||||
elsif Symbol === key.char and respond_to?(key.char, true)
|
||||
|
||||
if key.char.is_a?(Symbol)
|
||||
process_key(key.char, key.char)
|
||||
else
|
||||
normal_char(key)
|
||||
@ -1429,13 +1403,42 @@ class Reline::LineEditor
|
||||
end
|
||||
end
|
||||
|
||||
private def completion_journey_up(key)
|
||||
if not @config.disable_completion and @config.autocompletion
|
||||
private def complete(_key)
|
||||
return if @config.disable_completion
|
||||
|
||||
process_insert(force: true)
|
||||
if @config.autocompletion
|
||||
@completion_state = CompletionState::NORMAL
|
||||
@completion_occurs = move_completed_list(:up)
|
||||
@completion_occurs = move_completed_list(:down)
|
||||
else
|
||||
@completion_journey_state = nil
|
||||
result = call_completion_proc
|
||||
if result.is_a?(Array)
|
||||
@completion_occurs = true
|
||||
perform_completion(result, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
alias_method :menu_complete_backward, :completion_journey_up
|
||||
|
||||
private def completion_journey_move(direction)
|
||||
return if @config.disable_completion
|
||||
|
||||
process_insert(force: true)
|
||||
@completion_state = CompletionState::NORMAL
|
||||
@completion_occurs = move_completed_list(direction)
|
||||
end
|
||||
|
||||
private def menu_complete(_key)
|
||||
completion_journey_move(:down)
|
||||
end
|
||||
|
||||
private def menu_complete_backward(_key)
|
||||
completion_journey_move(:up)
|
||||
end
|
||||
|
||||
private def completion_journey_up(_key)
|
||||
completion_journey_move(:up) if @config.autocompletion
|
||||
end
|
||||
|
||||
# Editline:: +ed-unassigned+ This editor command always results in an error.
|
||||
# GNU Readline:: There is no corresponding macro.
|
||||
@ -1904,7 +1907,7 @@ class Reline::LineEditor
|
||||
elsif !@config.autocompletion # show completed list
|
||||
result = call_completion_proc
|
||||
if result.is_a?(Array)
|
||||
complete(result, true)
|
||||
perform_completion(result, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -787,9 +787,22 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
||||
input_keys('b')
|
||||
input_keys("\C-i", false)
|
||||
assert_line_around_cursor('foo_ba', '')
|
||||
input_keys("\C-h")
|
||||
input_key_by_symbol(:complete)
|
||||
assert_line_around_cursor('foo_ba', '')
|
||||
input_keys("\C-h", false)
|
||||
input_key_by_symbol(:menu_complete)
|
||||
assert_line_around_cursor('foo_bar', '')
|
||||
input_key_by_symbol(:menu_complete)
|
||||
assert_line_around_cursor('foo_baz', '')
|
||||
input_keys("\C-h", false)
|
||||
input_key_by_symbol(:menu_complete_backward)
|
||||
assert_line_around_cursor('foo_baz', '')
|
||||
input_key_by_symbol(:menu_complete_backward)
|
||||
assert_line_around_cursor('foo_bar', '')
|
||||
end
|
||||
|
||||
def test_autocompletion_with_upward_navigation
|
||||
def test_autocompletion
|
||||
@config.autocompletion = true
|
||||
@line_editor.completion_proc = proc { |word|
|
||||
%w{
|
||||
@ -806,31 +819,14 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
||||
assert_line_around_cursor('Readline', '')
|
||||
input_keys("\C-i", false)
|
||||
assert_line_around_cursor('Regexp', '')
|
||||
@line_editor.input_key(Reline::Key.new(:completion_journey_up, :completion_journey_up, false))
|
||||
input_key_by_symbol(:completion_journey_up)
|
||||
assert_line_around_cursor('Readline', '')
|
||||
ensure
|
||||
@config.autocompletion = false
|
||||
end
|
||||
|
||||
def test_autocompletion_with_upward_navigation_and_menu_complete_backward
|
||||
@config.autocompletion = true
|
||||
@line_editor.completion_proc = proc { |word|
|
||||
%w{
|
||||
Readline
|
||||
Regexp
|
||||
RegexpError
|
||||
}.map { |i|
|
||||
i.encode(@encoding)
|
||||
}
|
||||
}
|
||||
input_keys('Re')
|
||||
assert_line_around_cursor('Re', '')
|
||||
input_keys("\C-i", false)
|
||||
assert_line_around_cursor('Readline', '')
|
||||
input_keys("\C-i", false)
|
||||
input_key_by_symbol(:complete)
|
||||
assert_line_around_cursor('Regexp', '')
|
||||
@line_editor.input_key(Reline::Key.new(:menu_complete_backward, :menu_complete_backward, false))
|
||||
input_key_by_symbol(:menu_complete_backward)
|
||||
assert_line_around_cursor('Readline', '')
|
||||
input_key_by_symbol(:menu_complete)
|
||||
assert_line_around_cursor('Regexp', '')
|
||||
ensure
|
||||
@config.autocompletion = false
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user