Skip to content

Commit

Permalink
disable hints during non-bracketed paste
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Dec 23, 2024
1 parent 03017db commit 549ba7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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 || !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 = false
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

0 comments on commit 549ba7e

Please sign in to comment.