Skip to content

Commit 04ef6c2

Browse files
authored
Right arrow autocompletes at line end (#54983)
This commit adds a REPL feature: autocompletion when the right arrow key is pressed at the end of a line (The current behavior is to do nothing). This new effect only occurs when: - the cursor is at the end of the buffer, - there is only one possible completion, and - more than 1 character is in the buffer. In this situation, the right arrow key behaves like `<Tab>`. Otherwise, the right arrow key behaves as normal. The feature was requested in #54539 and seems intuitive to me. One useful side effect is that, by requiring that the cursor be at the end of the line, it offers a way to avoid autcompletes within words, which I assume are almost never helpful (For example, if I type "show" in the REPL, move the cursor onto the 'o' and press `<Tab>`, I end up with "showow"). One potential drawback is that the autocomplete could occur when a user who simply wants to move the cursor to the end of the line holds down the right arrow.
1 parent 9dd49c0 commit 04ef6c2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

stdlib/REPL/src/LineEdit.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,26 @@ function edit_move_right(buf::IOBuffer)
741741
end
742742
return false
743743
end
744-
edit_move_right(s::PromptState) = edit_move_right(s.input_buffer) ? refresh_line(s) : false
744+
function edit_move_right(m::MIState)
745+
s = state(m)
746+
buf = s.input_buffer
747+
if edit_move_right(s.input_buffer)
748+
refresh_line(s)
749+
return true
750+
else
751+
completions, partial, should_complete = complete_line(s.p.complete, s, m.active_module)
752+
if should_complete && eof(buf) && length(completions) == 1 && length(partial) > 1
753+
# Replace word by completion
754+
prev_pos = position(s)
755+
push_undo(s)
756+
edit_splice!(s, (prev_pos - sizeof(partial)) => prev_pos, completions[1])
757+
refresh_line(state(s))
758+
return true
759+
else
760+
return false
761+
end
762+
end
763+
end
745764

746765
function edit_move_word_right(s::PromptState)
747766
if !eof(s.input_buffer)

0 commit comments

Comments
 (0)