Skip to content

Commit

Permalink
append completion_append_character only when continous completion is … (
Browse files Browse the repository at this point in the history
#764)

* append completion_append_character only when continous completion is not possible

* refactoring

* remove debug puts
  • Loading branch information
monkeyWzr authored Oct 24, 2024
1 parent f09772a commit 01872fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 15 additions & 12 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def editing_mode

private def complete_internal_proc(list, is_menu)
preposing, target, postposing = retrieve_completion_block
list = list.select { |i|
candidates = list.select { |i|
if i and not Encoding.compatible?(target.encoding, i.encoding)
raise Encoding::CompatibilityError, "#{target.encoding.name} is not compatible with #{i.encoding.name}"
end
Expand All @@ -811,10 +811,10 @@ def editing_mode
end
}.uniq
if is_menu
menu(target, list)
menu(target, candidates)
return nil
end
completed = list.inject { |memo, item|
completed = candidates.inject { |memo, item|
begin
memo_mbchars = memo.unicode_normalize.grapheme_clusters
item_mbchars = item.unicode_normalize.grapheme_clusters
Expand All @@ -841,7 +841,8 @@ def editing_mode
end
result
}
[target, preposing, completed, postposing]

[target, preposing, completed, postposing, candidates]
end

private def perform_completion(list, just_show_list)
Expand Down Expand Up @@ -869,24 +870,26 @@ def editing_mode
@completion_state = CompletionState::PERFECT_MATCH
end
return if result.nil?
target, preposing, completed, postposing = result
target, preposing, completed, postposing, candidates = result
return if completed.nil?
if target <= completed and (@completion_state == CompletionState::COMPLETION)
if list.include?(completed)
if list.one?
append_character = ''
if candidates.include?(completed)
if candidates.one?
append_character = completion_append_character.to_s
@completion_state = CompletionState::PERFECT_MATCH
else
@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
@perfect_matched = completed
else
@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
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)
line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: encoding)
unless just_show_list
@buffer_of_lines[@line_index] = (preposing + completed + append_character + postposing).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
end
end
Expand Down
4 changes: 0 additions & 4 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,6 @@ def test_completion_with_perfect_match
input_keys('_')
input_keys("\C-i", false)
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(nil, matched)
input_keys("\C-i", false)
Expand Down

0 comments on commit 01872fd

Please sign in to comment.