Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REPL] Confusing completion when using up arrow and TAB #52264

Closed
giordano opened this issue Nov 21, 2023 · 9 comments · Fixed by #53662
Closed

[REPL] Confusing completion when using up arrow and TAB #52264

giordano opened this issue Nov 21, 2023 · 9 comments · Fixed by #53662
Labels
kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version stdlib:REPL Julia's REPL (Read Eval Print Loop)
Milestone

Comments

@giordano
Copy link
Contributor

Imagine this REPL session with Julia master, | represents the position of the cursor

using Linea|
# Now press up arrow to recall previous item in the history starting with `using Linea`
# This is completed to...
using Linea|rAlgebra
# Now press TAB
using LinearAlgebra|
# Now press TAB again
using LinearAlgebra|rAlgebra

Ideally last TAB shouldn't do anything, as the cursor is already at the end of the line and there's nothing to complete there.

In Julia v1.9, after pressing the up arrow the TAB key completes

using Linea|rAlgebra

to

using LinearAlgebra|rAlgebra

which makes sense because you're basically completing using Linea, but the behaviour on master is much more counterintuitive because pressing TAB the first time moves the cursor at the end of the line, so another TAB shouldn't do anything at that point.

@giordano giordano added kind:bug Indicates an unexpected problem or unintended behavior stdlib:REPL Julia's REPL (Read Eval Print Loop) kind:regression Regression in behavior compared to a previous version labels Nov 21, 2023
@AshlinHarris
Copy link
Contributor

AshlinHarris commented Nov 22, 2023

Replacing that final Tab press with almost any keypress (left or right arrow, ENTER, any number or letter) produces a similar result:

# start by running VERSION, then type VE + Up Arrow + Tab

julia> VERSION |RSION # result of typing Space

julia> VERSIO|NRSION # result of typing Left Arrow

julia> VERSIONR|SION # result of typing Right Arrow

# result of typing Enter
julia> VERSIONRSION
ERROR: UndefVarError: `VERSIONRSION` not defined in `Main`
Suggestion: check for spelling errors or missing imports. No global of this name exists in this module.

Something related happens with only the arrow keys. After typing the first few letters of the command and pressing the Up arrow, pressing Left or Right will hide all the characters after the cursor. Pressing Left or Right again will make them visible again.

In each case, the final behavior is the same between release v1.9 and the master branch. Apparently, the first button press is still creating the same string as in 1.9, but now it just isn't displaying properly until another key is pressed. So maybe the string display isn't being refreshed?

@AshlinHarris
Copy link
Contributor

AshlinHarris commented Nov 23, 2023

This could be an effect of the Tab completion hints. Reverting that commit (or resetting LineEdit.jl to the previous version) restores the previous behavior.

@giordano
Copy link
Contributor Author

CC @IanButterworth

@giordano giordano added this to the 1.11 milestone Nov 23, 2023
@Liozou
Copy link
Member

Liozou commented Dec 25, 2023

Instead of reverting the entire commit, it is sufficient to remove the following line:

diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl
index 709eeaa285..c20d90e7c5 100644
--- a/stdlib/REPL/src/LineEdit.jl
+++ b/stdlib/REPL/src/LineEdit.jl
@@ -482,7 +482,6 @@ function maybe_show_hint(s::PromptState)
     # The hint being "" then nothing is used to first clear a previous hint, then skip printing the hint
     # the clear line cannot be printed each time because it breaks column movement
     if isempty(s.hint)
-        print(terminal(s), "\e[0K") # clear remainder of line which had a hint
         s.hint = nothing
     else
         Base.printstyled(terminal(s), s.hint, color=:light_black)

However, I don't have a clear idea what was the intent behind that line originally, so removing it may not be a good idea... And I can't manage to add a proper test that works after the fix but not before. @IanButterworth, sorry for the second ping on that issue but do you have any hint regarding this?

@IanButterworth
Copy link
Sponsor Member

I think all of this would be fixed from a UX perspective by turning off tab completion when you're in the middle of an entry..

Like, it doesn't make any sense to me that pressing tab here

using Linea|rAlgebra

turns into

using LinearAlgebra|rAlgebra

So just disable tab completion when not at the end of an entry? Or is there some valid reason to keep it?

@KristofferC
Copy link
Sponsor Member

I guess one possible improvement is if you are at

"foo|bar

and pressing tab would complete to "foobarxxx then "absorbing the bar in that tab complete would feel natural so after that tab you have "foobarxxx| (instead of foobarxxx|bar.

@iagobaapellaniz
Copy link
Contributor

I think if one presses UP to recall used entries, the cursor should be placed at the end of the prompts.

Would that fix the bug?

@IanButterworth
Copy link
Sponsor Member

That makes sense for one up press but doesn't for more than that because it would need to then complete the full entry from the first up

@iagobaapellaniz
Copy link
Contributor

When the prompt is empty, and one presses the key up several times, it does place the cursor at the end of the prompt always. Maybe partial entries and empty ones should behave similarly. The REPL could place the cursor at the end remembering which part has been inserted by hand.

vtjnash added a commit that referenced this issue Mar 8, 2024
The hint must be cleared before the screen state is reset, otherwise the
state after reset may not be compatible with being able to clear it.

Fixes #52264
vtjnash added a commit that referenced this issue Mar 11, 2024
The hint must be cleared before the screen state is reset, otherwise the
state after reset may not be compatible with being able to clear it.

Fixes #52264
KristofferC pushed a commit that referenced this issue Mar 15, 2024
The hint must be cleared before the screen state is reset, otherwise the
state after reset may not be compatible with being able to clear it.

Fixes #52264

(cherry picked from commit 2978a64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version stdlib:REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants