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: Disable hints during non-bracketed paste #56895

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ end

function check_for_hint(s::MIState)
st = state(s)
if !options(st).hint_tab_completes || !eof(buffer(st))
if options(st).hint_tab_completes_tmp_off || !options(st).hint_tab_completes || !eof(buffer(st))
# only generate hints if enabled and at the end of the line
# TODO: maybe show hints for insertions at other positions
# Requires making space for them earlier in refresh_multi_line
Expand Down Expand Up @@ -917,16 +917,22 @@ function edit_insert(s::PromptState, c::StringLike)
if pos > 0
if buf.data[pos] != _space && string(c) != " "
options(s).auto_indent_tmp_off = false
options(s).hint_tab_completes_tmp_off = false
end
if buf.data[pos] == _space
#tabulators are already expanded to space
#this expansion may take longer than auto_indent_time_threshold which breaks the timing
s.last_newline = time()
else
#if characters after new line are coming in very fast
#its probably copy&paste => switch auto-indent off for the next coming new line
if ! options(s).auto_indent_tmp_off && time() - s.last_newline < options(s).auto_indent_time_threshold
options(s).auto_indent_tmp_off = true
#its probably copy&paste => switch auto-indent and tab hinting off for the next coming new line
if time() - s.last_newline < options(s).auto_indent_time_threshold
if !options(s).auto_indent_tmp_off
options(s).auto_indent_tmp_off = true
end
if !options(s).hint_tab_completes_tmp_off
options(s).hint_tab_completes_tmp_off = true
end
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion stdlib/REPL/src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mutable struct Options
# refresh after time delay
auto_refresh_time_delay::Float64
hint_tab_completes::Bool
hint_tab_completes_tmp_off::Bool
# default IOContext settings at the REPL
iocontext::Dict{Symbol,Any}
end
Expand All @@ -49,6 +50,7 @@ Options(;
auto_indent_time_threshold = 0.005,
auto_refresh_time_delay = Sys.iswindows() ? 0.05 : 0.0,
hint_tab_completes = true,
hint_tab_completes_tmp_off = false, # internal
iocontext = Dict{Symbol,Any}()) =
Options(hascolor, extra_keymap, tabwidth,
kill_ring_max, region_animation_duration,
Expand All @@ -57,7 +59,7 @@ Options(;
backspace_align, backspace_adjust, confirm_exit,
auto_indent, auto_indent_tmp_off, auto_indent_bracketed_paste,
auto_indent_time_threshold, auto_refresh_time_delay,
hint_tab_completes,
hint_tab_completes, hint_tab_completes_tmp_off,
iocontext)

# for use by REPLs not having an options field
Expand Down
Loading