append completion_append_character only when continous completion is … (#764)

* append completion_append_character only when continous completion is not possible

* refactoring

* remove debug puts
This commit is contained in:
Wu 2024-10-24 23:12:37 +09:00 коммит произвёл git
Родитель c1ca331cf4
Коммит 78378cae66
2 изменённых файлов: 15 добавлений и 16 удалений

Просмотреть файл

@ -800,7 +800,7 @@ class Reline::LineEditor
private def complete_internal_proc(list, is_menu) private def complete_internal_proc(list, is_menu)
preposing, target, postposing = retrieve_completion_block preposing, target, postposing = retrieve_completion_block
list = list.select { |i| candidates = list.select { |i|
if i and not Encoding.compatible?(target.encoding, i.encoding) if i and not Encoding.compatible?(target.encoding, i.encoding)
raise Encoding::CompatibilityError, "#{target.encoding.name} is not compatible with #{i.encoding.name}" raise Encoding::CompatibilityError, "#{target.encoding.name} is not compatible with #{i.encoding.name}"
end end
@ -811,10 +811,10 @@ class Reline::LineEditor
end end
}.uniq }.uniq
if is_menu if is_menu
menu(target, list) menu(target, candidates)
return nil return nil
end end
completed = list.inject { |memo, item| completed = candidates.inject { |memo, item|
begin begin
memo_mbchars = memo.unicode_normalize.grapheme_clusters memo_mbchars = memo.unicode_normalize.grapheme_clusters
item_mbchars = item.unicode_normalize.grapheme_clusters item_mbchars = item.unicode_normalize.grapheme_clusters
@ -841,7 +841,8 @@ class Reline::LineEditor
end end
result result
} }
[target, preposing, completed, postposing]
[target, preposing, completed, postposing, candidates]
end end
private def perform_completion(list, just_show_list) private def perform_completion(list, just_show_list)
@ -869,24 +870,26 @@ class Reline::LineEditor
@completion_state = CompletionState::PERFECT_MATCH @completion_state = CompletionState::PERFECT_MATCH
end end
return if result.nil? return if result.nil?
target, preposing, completed, postposing = result target, preposing, completed, postposing, candidates = result
return if completed.nil? return if completed.nil?
if target <= completed and (@completion_state == CompletionState::COMPLETION) if target <= completed and (@completion_state == CompletionState::COMPLETION)
if list.include?(completed) append_character = ''
if list.one? if candidates.include?(completed)
if candidates.one?
append_character = completion_append_character.to_s
@completion_state = CompletionState::PERFECT_MATCH @completion_state = CompletionState::PERFECT_MATCH
else else
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH @completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
perform_completion(list, true) if @config.show_all_if_ambiguous perform_completion(candidates, true) if @config.show_all_if_ambiguous
end end
@perfect_matched = completed @perfect_matched = completed
else else
@completion_state = CompletionState::MENU @completion_state = CompletionState::MENU
perform_completion(list, true) if @config.show_all_if_ambiguous perform_completion(candidates, true) if @config.show_all_if_ambiguous
end end
if not just_show_list and target < completed unless just_show_list
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: encoding) @buffer_of_lines[@line_index] = (preposing + completed + append_character + postposing).split("\n")[@line_index] || String.new(encoding: encoding)
line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: encoding) line_to_pointer = (preposing + completed + append_character).split("\n")[@line_index] || String.new(encoding: encoding)
@byte_pointer = line_to_pointer.bytesize @byte_pointer = line_to_pointer.bytesize
end end
end end

Просмотреть файл

@ -908,10 +908,6 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase
input_keys('_') input_keys('_')
input_keys("\C-i", false) input_keys("\C-i", false)
assert_line_around_cursor('foo_bar', '') assert_line_around_cursor('foo_bar', '')
assert_equal(Reline::LineEditor::CompletionState::MENU_WITH_PERFECT_MATCH, @line_editor.instance_variable_get(:@completion_state))
assert_equal(nil, matched)
input_keys("\C-i", false)
assert_line_around_cursor('foo_bar', '')
assert_equal(Reline::LineEditor::CompletionState::PERFECT_MATCH, @line_editor.instance_variable_get(:@completion_state)) assert_equal(Reline::LineEditor::CompletionState::PERFECT_MATCH, @line_editor.instance_variable_get(:@completion_state))
assert_equal(nil, matched) assert_equal(nil, matched)
input_keys("\C-i", false) input_keys("\C-i", false)