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

Fix moving up and down in REPL #350

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Changes from 2 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
9 changes: 6 additions & 3 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,13 @@ end
NEW_KEYBINDINGS = create_keybindings()

function insert_keybindings(repl = Base.active_repl)
mirepl = isdefined(repl,:mi) ? repl.mi : repl
main_mode = mirepl.interface.modes[1]
p = mirepl.interface.modes[5]
mirepl = isdefined(repl,:mistate) ? repl.mistate : repl
interface_modes = mirepl.interface.modes
main_mode = interface_modes[1]
php_idx = findfirst(isa.(interface_modes, LineEdit.PrefixHistoryPrompt))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
php_idx = findfirst(isa.(interface_modes, LineEdit.PrefixHistoryPrompt))
php_idx = findfirst(isa(LineEdit.PrefixHistoryPrompt), interface_modes)

Avoid allocating

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, isa requires two arguments explicitly. Here is a workaround:

findfirst(Base.Fix2(isa, LineEdit.PrefixHistoryPrompt), interface_modes)

However, I'm uncertain about using Base.Fix2 since it hasn't been exported.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. It's fine to use Fix2, it's public, just not exported https://docs.julialang.org/en/v1/base/base/#Base.Fix2

p = interface_modes[php_idx]

# Up Arrow
NEW_KEYBINDINGS["\e[A"] = (s,o...)-> begin
LineEdit.edit_move_up(buffer(s)) || LineEdit.enter_prefix_search(s, p, true)
Prompt.rewrite_with_ANSI(s)
Expand Down