Skip to content

Commit 01872fd

Browse files
authored
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
1 parent f09772a commit 01872fd

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

lib/reline/line_editor.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def editing_mode
800800

801801
private def complete_internal_proc(list, is_menu)
802802
preposing, target, postposing = retrieve_completion_block
803-
list = list.select { |i|
803+
candidates = list.select { |i|
804804
if i and not Encoding.compatible?(target.encoding, i.encoding)
805805
raise Encoding::CompatibilityError, "#{target.encoding.name} is not compatible with #{i.encoding.name}"
806806
end
@@ -811,10 +811,10 @@ def editing_mode
811811
end
812812
}.uniq
813813
if is_menu
814-
menu(target, list)
814+
menu(target, candidates)
815815
return nil
816816
end
817-
completed = list.inject { |memo, item|
817+
completed = candidates.inject { |memo, item|
818818
begin
819819
memo_mbchars = memo.unicode_normalize.grapheme_clusters
820820
item_mbchars = item.unicode_normalize.grapheme_clusters
@@ -841,7 +841,8 @@ def editing_mode
841841
end
842842
result
843843
}
844-
[target, preposing, completed, postposing]
844+
845+
[target, preposing, completed, postposing, candidates]
845846
end
846847

847848
private def perform_completion(list, just_show_list)
@@ -869,24 +870,26 @@ def editing_mode
869870
@completion_state = CompletionState::PERFECT_MATCH
870871
end
871872
return if result.nil?
872-
target, preposing, completed, postposing = result
873+
target, preposing, completed, postposing, candidates = result
873874
return if completed.nil?
874875
if target <= completed and (@completion_state == CompletionState::COMPLETION)
875-
if list.include?(completed)
876-
if list.one?
876+
append_character = ''
877+
if candidates.include?(completed)
878+
if candidates.one?
879+
append_character = completion_append_character.to_s
877880
@completion_state = CompletionState::PERFECT_MATCH
878881
else
879882
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
880-
perform_completion(list, true) if @config.show_all_if_ambiguous
883+
perform_completion(candidates, true) if @config.show_all_if_ambiguous
881884
end
882885
@perfect_matched = completed
883886
else
884887
@completion_state = CompletionState::MENU
885-
perform_completion(list, true) if @config.show_all_if_ambiguous
888+
perform_completion(candidates, true) if @config.show_all_if_ambiguous
886889
end
887-
if not just_show_list and target < completed
888-
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: encoding)
889-
line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: encoding)
890+
unless just_show_list
891+
@buffer_of_lines[@line_index] = (preposing + completed + append_character + postposing).split("\n")[@line_index] || String.new(encoding: encoding)
892+
line_to_pointer = (preposing + completed + append_character).split("\n")[@line_index] || String.new(encoding: encoding)
890893
@byte_pointer = line_to_pointer.bytesize
891894
end
892895
end

test/reline/test_key_actor_emacs.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,6 @@ def test_completion_with_perfect_match
908908
input_keys('_')
909909
input_keys("\C-i", false)
910910
assert_line_around_cursor('foo_bar', '')
911-
assert_equal(Reline::LineEditor::CompletionState::MENU_WITH_PERFECT_MATCH, @line_editor.instance_variable_get(:@completion_state))
912-
assert_equal(nil, matched)
913-
input_keys("\C-i", false)
914-
assert_line_around_cursor('foo_bar', '')
915911
assert_equal(Reline::LineEditor::CompletionState::PERFECT_MATCH, @line_editor.instance_variable_get(:@completion_state))
916912
assert_equal(nil, matched)
917913
input_keys("\C-i", false)

0 commit comments

Comments
 (0)