Weird output with REPL escape codes

Didn’t you also replace cariage returns with new lines?
What I get looks like this (with escape characters replaced by \e and carriage returns replaced by \r):

\e[?2004h\r\e[0Kjulia> \r\e[7C\r\e[7C1+2\r\e[0Kjulia> \r\e[7C1+2\r\e[10C
\e[?2004l3

\r\e[0K\r\e[0Kjulia> \r\e[7C\r\e[7C\e[?2004h\r\e[0Kjulia> \r\e[7C\r\e[7C
\e[?2004l

This makes more sense, because now the CRs make the cursor move backward to the beginning of the line. The echo output also agrees with cat:

shell$ echo -e '\e[?2004h\r\e[0Kjulia> \r\e[7C\r\e[7C1+2\r\e[0Kjulia> \r\e[7C1+2\r\e[10C
> \e[?2004l3
> 
> \r\e[0K\r\e[0Kjulia> \r\e[7C\r\e[7C\e[?2004h\r\e[0Kjulia> \r\e[7C\r\e[7C
> \e[?2004l'
julia> 1+2
3

julia> 

However, I don’t know why the prompt is repeated twice (but erased right after it’s printed for the first time). An other peculiarity is how the bracketed paste mode sequences (\e?2004h and \e?2004l) encompass both prompts in the first line, but only one in the second line.