Skip to content

Commit 14ff02f

Browse files
committed
only remove prompt prefix in bracket paste
1 parent 741b41d commit 14ff02f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

base/LineEdit.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,14 @@ Must satisfy `0 < tabwidth <= 16`.
13021302
"""
13031303
global tabwidth = 8
13041304

1305+
const STANDARD_REPL_PROMPTS = ["julia> ", "help?> ", "shell> "]
1306+
13051307
function bracketed_paste(s)
13061308
ps = state(s, mode(s))
13071309
input = readuntil(ps.terminal, "\e[201~")[1:(end-6)]
1310+
if ps.p.prompt in STANDARD_REPL_PROMPTS && startswith(input, ps.p.prompt)
1311+
input = input[sizeof(ps.p.prompt)+1:end]
1312+
end
13081313
input = replace(input, '\r', '\n')
13091314
if position(buffer(s)) == 0
13101315
indent = Base.indentation(input; tabwidth=tabwidth)[1]

base/REPL.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,18 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
832832
oldpos = start(input)
833833
firstline = true
834834
while !done(input, oldpos) # loop until all lines have been executed
835-
if startswith(input, "julia> ")
836-
input = input[8:end]
835+
# Check if the next statement starts with "julia> ", in that case
836+
# skip it.
837+
# First skip and count newline characters
838+
c = oldpos
839+
while c <= sizeof(input) && input[c] == '\n'
840+
c = nextind(input, c)
841+
end
842+
n_newlines = c - oldpos
843+
# Skip over prompt prefix if statement starts with it
844+
jl_prompt_len = 7
845+
if c + jl_prompt_len <= sizeof(input) && input[c:c+jl_prompt_len-1] == "julia> "
846+
oldpos += jl_prompt_len + n_newlines
837847
end
838848
ast, pos = Base.syntax_deprecation_warnings(false) do
839849
Base.parse(input, oldpos, raise=false)

0 commit comments

Comments
 (0)