Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/reader_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ module Reply
reader.auto_completion.verify(open: true, entries: %w(hello hey), name_filter: "h", selection_pos: 0)
reader.editor.verify("42.hello")

SpecHelper.send(pipe_in, "\e\t") # shit_tab
SpecHelper.send(pipe_in, "\e\t") # shift_tab
Copy link
Author

Choose a reason for hiding this comment

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

Was trying to find somewhere to add a spec for this change and discovered this amusing typo

Copy link
Owner

Choose a reason for hiding this comment

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

Oups -__-

reader.auto_completion.verify(open: true, entries: %w(hello hey), name_filter: "h", selection_pos: 1)
reader.editor.verify("42.hey")

Expand Down
30 changes: 21 additions & 9 deletions src/reader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,18 @@ module Reply
if @auto_completion.open?
if shift_tab
replacement = @auto_completion.selection_previous
elsif current_word.ends_with?("::")
@auto_completion.close
replacement = compute_completions(current_word, word_begin)
else
replacement = @auto_completion.selection_next
if replacement.try(&.count("::")) != current_word.count("::")
@auto_completion.close
replacement = compute_completions(current_word, word_begin)
end
end
else
# Get whole expression before cursor, allow auto-completion to deduce the receiver type
expr = @editor.expression_before_cursor(x: word_begin)

# Compute auto-completion, return `replacement` (`nil` if no entry, full name if only one entry, or the begin match of entries otherwise)
replacement = @auto_completion.complete_on(current_word, expr)

if replacement && @auto_completion.entries.size >= 2
@auto_completion.open
end
replacement = compute_completions(current_word, word_begin)
end

# Replace the current_word by the replacement word
Expand All @@ -392,6 +391,19 @@ module Reply
end
end

private def compute_completions(current_word, word_begin) : String?
expr = @editor.expression_before_cursor(x: word_begin)

# Compute auto-completion, return `replacement` (`nil` if no entry, full name if only one entry, or the begin match of entries otherwise)
replacement = @auto_completion.complete_on(current_word, expr)

if replacement && @auto_completion.entries.size >= 2
@auto_completion.open
end

replacement
end

private def on_escape
@auto_completion.close
@editor.update
Expand Down