Skip to content

append completion_append_character only when continous completion is … - #764

Merged
tompng merged 4 commits into
ruby:masterfrom
monkeyWzr:append_completion_append_character_only_when_necessary
Oct 24, 2024
Merged

tompng merged 4 commits into
ruby:masterfrom
monkeyWzr:append_completion_append_character_only_when_necessary

Conversation

@monkeyWzr

Copy link
Copy Markdown
Contributor

Fix #754. Insert completion_append_character only when there is no more possible completion

Comment thread lib/reline/line_editor.rb Outdated
end
return if result.nil?
target, preposing, completed, postposing = result
target, preposing, completed, postposing, continuable = result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuable in calculated twice.
One in complete_internal_proc(list.count > 1) and other in this method

if list.one?
  @completion_state = CompletionState::PERFECT_MATCH

How about using the condition @completion_state != CompletionState::PERFECT_MATCH instead of continuable, or set a local variable inside if list.one?

if list.one?
  @completion_state = CompletionState::PERFECT_MATCH
  perfect_matched_and_need_to_perform_append_char = true # FIXME: shorter name
end

@monkeyWzr monkeyWzr Oct 19, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion! But consider this case when list is something like:

['foo', 'foo_bar']

When we input foo_[tab], it will be completed to foo_bar. A completion char should be appended but currently this case will be marked as MENU_WITH_PERFECT_MATCH. That's why I separately check list.count instead of inside if list.one? case.

After reconsideration, I think maybe it's OK to treat the above case as a PERFECT_MATCH?

(For demonstration I made the changes anyway. Looking forward to you comment! )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating it as PERFECT_MATCH makes sense to me 👍

Comment thread lib/reline/line_editor.rb Outdated
@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
_completion_append_character = continuable ? '' : completion_append_character.to_s

@tompng tompng Oct 19, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underscore prefixed local variable represents unused variable. Ruby itself won't show unused variable warning if the unused variable starts with _. If it is used, it is better not start with _.
How about just append_character or completed += completion_append_character.to_s unless continuable

@tompng

tompng commented Oct 22, 2024

Copy link
Copy Markdown
Member

The change looks good. Could you resolve conflicts?

@tompng tompng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@tompng
tompng merged commit 01872fd into ruby:master Oct 24, 2024
@ima1zumi ima1zumi added the bug Something isn't working label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected completion_append_character when tab-completing

3 participants