Skip to content

Commit 4e2b095

Browse files
committed
Add right arrow and end as completion keys
1 parent 3e7cf64 commit 4e2b095

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

stdlib/REPL/src/LineEdit.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,9 @@ function bracketed_paste(s::MIState; tabwidth::Int=options(s).tabwidth)
24942494
return replace(input, '\t' => " "^tabwidth)
24952495
end
24962496

2497-
function tab_should_complete(s::MIState)
2497+
# `key` can either be the tab-completer key if that is a valid textual key or `nothing`
2498+
# if the completer key can't be entered into text.
2499+
function key_should_complete(s::MIState, key::Union{Char,Nothing})
24982500
# Yes, we are ignoring the possibility
24992501
# the we could be in the middle of a multi-byte
25002502
# sequence, here but that's ok, since any
@@ -2503,7 +2505,8 @@ function tab_should_complete(s::MIState)
25032505
pos = position(buf)
25042506
pos == 0 && return true
25052507
c = buf.data[pos]
2506-
return c != _newline && c != UInt8('\t') &&
2508+
not_completer_key = key === nothing ? true : c != UInt8(key)
2509+
return c != _newline && not_completer_key &&
25072510
# hack to allow path completion in cmds
25082511
# after a space, e.g., `cd <tab>`, while still
25092512
# allowing multiple indent levels
@@ -2513,7 +2516,6 @@ end
25132516
# jump_spaces: if cursor is on a ' ', move it to the first non-' ' char on the right
25142517
# if `delete_trailing`, ignore trailing ' ' by deleting them
25152518
function edit_tab(s::MIState, jump_spaces::Bool=false, delete_trailing::Bool=jump_spaces)
2516-
tab_should_complete(s) && return complete_line(s)
25172519
set_action!(s, :edit_insert_tab)
25182520
push_undo(s)
25192521
edit_insert_tab(buffer(s), jump_spaces, delete_trailing) || pop_undo(s)
@@ -2559,7 +2561,7 @@ end
25592561
const default_keymap =
25602562
AnyDict(
25612563
# Tab
2562-
'\t' => (s::MIState,o...)->edit_tab(s, true),
2564+
'\t' => (s::MIState,o...)->(key_should_complete(s, '\t') ? complete_line(s) : edit_tab(s, true)),
25632565
# Shift-tab
25642566
"\e[Z" => (s::MIState,o...)->shift_tab_completion(s),
25652567
# Enter
@@ -2651,7 +2653,7 @@ AnyDict(
26512653
end,
26522654
"^Z" => (s::MIState,o...)->(return :suspend),
26532655
# Right Arrow
2654-
"\e[C" => (s::MIState,o...)->edit_move_right(s),
2656+
"\e[C" => (s::MIState,o...)->(key_should_complete(s, nothing) ? complete_line(s) : edit_move_right(s)),
26552657
# Left Arrow
26562658
"\e[D" => (s::MIState,o...)->edit_move_left(s),
26572659
# Up Arrow
@@ -2675,7 +2677,9 @@ AnyDict(
26752677
"\el" => (s::MIState,o...)->edit_lower_case(s),
26762678
"\ec" => (s::MIState,o...)->edit_title_case(s),
26772679
"\ee" => (s::MIState,o...) -> edit_input(s),
2678-
"\em" => (s::MIState, o...) -> activate_module(s)
2680+
"\em" => (s::MIState, o...) -> activate_module(s),
2681+
# End
2682+
"\e[F" => (s::MIState, o...) -> (key_should_complete(s, nothing) && complete_line(s)),
26792683
)
26802684

26812685
const history_keymap = AnyDict(

0 commit comments

Comments
 (0)