-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Rf/autoindentpaste improvements #30755
Conversation
On some Windows terminals, pasting is not recognized as such. This happens also with tmux' builtin paste. In those cases, auto-indent is better disabled, as we want to preserve the original indentation of the code being pasted. This fix is quite a hack, but seems to work: using time(), if the next character after a newline is being inserted very fast, assume this was with paste, and cancel the insertion of the spaces done by auto-indent. I couldn't insert two characters in a raw within less than about 0.03 or 0.02 seconds, so the threshold for "very fast" is set to 0.0005, but this is an option which can changed.
* don't include refresh_line in the timings * use a separate autoindent variable, as we want to undo indent in case of paste only for auto-indented code (although currently in the REPL code this function is never called with a positive argument)
…one. Paste of mixed space/tabs/empty lines is now more reliable.
pain... I will check for this :-( |
@@ -680,6 +682,27 @@ edit_splice!(s, ins::AbstractString) = edit_splice!(s, region(s), ins) | |||
function edit_insert(s::PromptState, c) | |||
push_undo(s) | |||
buf = s.input_buffer | |||
|
|||
if ! options(s).auto_indent_bracketed_paste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !options(s).auto_indent_bracketed_paste
@@ -680,6 +682,27 @@ edit_splice!(s, ins::AbstractString) = edit_splice!(s, region(s), ins) | |||
function edit_insert(s::PromptState, c) | |||
push_undo(s) | |||
buf = s.input_buffer | |||
|
|||
if ! options(s).auto_indent_bracketed_paste | |||
pos=position(buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pos = position(buf)
bump, this is an annoying issue when using the terminal. |
Yeah, I was planning on trying this out and merging this. Will do so now. |
I just tested this out, situation is improved but it's still not pasting everything in properly |
E.g. sometimes it pastes and indents it correctly other times it does whatever it wants to... |
I haven't tested the original PR that this is based on, however. |
Can you give some examples? Maybe there are still cases which fail. |
@oheil All I did was copy some code and repeatedly paste it into the terminal. |
I guess it could be the timing. If you like to, you may try out other thresholds, using e.g. |
I think we should try this for a while, it doesn't seem any worse locally. If it leads to problems we can revert but things like this pretty much have to be tested in the wild. |
Improvements based on rf/autoindentpaste
https://github.com/JuliaLang/julia/tree/rf/autoindentpaste
For additional issues which are solved by this PR see
https://discourse.julialang.org/t/repl-copy-paste-and-auto-indent-in-julia-0-7/10230
e.g. pasting a mix of space and tabs and empty lines at once still break autoindentation
This PR replaces the PR of @rfourquet:
#29129