Skip to content

Commit 0f4baee

Browse files
authored
fix prompt-indentation when bracket pasting (#23406)
Cf. problem reported there: #22948 (comment) Bracket pasting was not removing the indentation corresponding to the prompt (i.e. 7 spaces for "julia> ").
1 parent 2767355 commit 0f4baee

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

base/repl/REPL.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,19 @@ function setup_interface(
889889
# (avoids modifying the user's current leading wip line)
890890
tail = lstrip(tail)
891891
end
892+
if isprompt_paste # remove indentation spaces corresponding to the prompt
893+
tail = replace(tail, r"^ {7}"m, "") # 7: jl_prompt_len
894+
end
892895
LineEdit.replace_line(s, tail)
893896
LineEdit.refresh_line(s)
894897
break
895898
end
896899
# get the line and strip leading and trailing whitespace
897900
line = strip(input[oldpos:prevind(input, pos)])
898901
if !isempty(line)
902+
if isprompt_paste # remove indentation spaces corresponding to the prompt
903+
line = replace(line, r"^ {7}"m, "") # 7: jl_prompt_len
904+
end
899905
# put the line on the screen and history
900906
LineEdit.replace_line(s, line)
901907
LineEdit.commit_line(s)

test/repl.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,18 @@ fake_repl() do stdin_write, stdout_read, repl
561561
wait(c)
562562
@test Main.A == 1
563563

564+
# Test that indentation corresponding to the prompt is removed
565+
sendrepl2("""\e[200~julia> begin\n α=1\n β=2\n end\n\e[201~""")
566+
wait(c)
567+
readuntil(stdout_read, "begin")
568+
@test readuntil(stdout_read, "end") == "\n\r\e[7C α=1\n\r\e[7C β=2\n\r\e[7Cend"
569+
# for incomplete input (`end` below is added after the end of bracket paste)
570+
sendrepl2("""\e[200~julia> begin\n α=1\n β=2\n\e[201~end""")
571+
wait(c)
572+
readuntil(stdout_read, "begin")
573+
readuntil(stdout_read, "begin")
574+
@test readuntil(stdout_read, "end") == "\n\r\e[7C α=1\n\r\e[7C β=2\n\r\e[7Cend"
575+
564576
# Close repl
565577
write(stdin_write, '\x04')
566578
wait(repltask)

0 commit comments

Comments
 (0)