-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Auto indent on paste behaves oddly with already indented lines. #5473
Comments
What version of Atom is this on? /cc @maxbrunsfeld |
Oops, should have included that. I'm using Mac 10.10.2 with Atom v0.177.0, but I've been experiencing this bug for a few versions now (not entirely sure when it first presented). Interesting, just tried to reproduce this on my Windows build box too. It has v0.175.0 installed. On that machine the behavior is reversed. When Auto Indent On Paste is enabled then pasting behaves as expected (each consecutive line is pasted at the same depth). However when that option is disabled then the first paste behaves as expected, but the 2nd through nth pastes are all one level deeper than the last. Not sure how to update the Windows version to see if it persists in 0.177.0. |
@NatalieWolfe I'm having trouble reproducing this in the latest version of Atom:
Here's what I'm doing: Is there something I'm doing differently than you are? Can you try reproducing this again and record a gif in which the invisible characters are shown as well as the keybinding resolver ( Atom should update to the latest version on its own, but you can download the latest version here as well: |
@izuzak: The link you provided goes to 0.179.0, which is what I have installed on my Mac at the moment. Here is an updated gif, starting from a completely new window. Auto Indent on Paste is enabled during this demonstration. If you would like me to make another where I type slower (so you have more time to see the keybinding resolver updates) let me know. |
I notice on your gif, @izuzak, that you are using a plain text file. I don't think Auto Indent on Paste works in plaintext files (there is no structure to the text for it to use). |
Ahhhh, that was it, thanks @NatalieWolfe! Seeing it now as well. |
I am running the current Atom (194) on Windows 7 and this issue persists. |
There are many indentation problems, and I'm trying to link all of them together in a single issue: here |
I'm finding that If I take this PHP method: public function name()
{
if ($something) {
return $something;
}
} And paste it into a PHP class, I get: public function name()
{
if ($something) {
return $something;
}
} So public function name()
{
if ($something) {
return $something;
}
} Beautiful, now it's properly intended for my PHP class. Auto indentation on paste is something PHPStorm does without flaw (see http://g.recordit.co/Rj6unPomlW.gif). It's weird that Atom can manually (For the record, I'm on Yosemite with Atom 1.0.9 in |
@jesseleite we used to do it the way you're suggesting: auto indent every line of the pasted text, but for many languages, our auto-indent is not smart enough to do it correctly, and people found it surprising that they code that they pasted was being altered like that. |
Would it be possible to read indenting rules from the current grammar? Landon Manning On 1 September 2015 at 13:55, Max Brunsfeld [email protected]
|
One thing for sure is that first line is problematic. If I had to copy JesseLeite I'd however agree that full blown aot indent is probably not what we want on paste, because we have no garantee user will only copy/paste properly matched block scope. So maybe block indent with overall indent information a bit smarter ? |
@maxbrunsfeld I see what you are saying. I would agree, that definitely is an issue. However, based on terminology, it's a very confusing inconsistency for the end user to understand: See what I'm getting at? |
Related comment: #4272 (comment) I think the desired behavior matches Sublime's |
I've created a solution to the problem with this pull request. To paraphrase, when text is copied starting with a newline character, a metadata member 'indentBasis' can be incorrect. More detail if you follow the link. My pull request needs testing on Windows! Can you guys help me out? |
A new PR is up with a fix: #12793. This bug has been bugging me for a long time now and would love to get it fixed. |
I've had another go at fixing this - see this package: https://atom.io/packages/fix-indent-on-paste |
Thanks @patstew. I had the feeling that this bug still persists even after a full year of development. Your package fixes atom which is now working as expected on my machine. Thanks! |
Thanks @patstew, your work made Atom much more usable for me. |
This is fucking awesome, thank you very much. |
@patstew Awesome, this has been bugging me for a while. I did notice one unexpected thing. When pasting over the existing block it removes the indent when it shouldn't. Not that this is a particularly realistic use case (why would you paste over a block with the same content). Just thought you might like to know. See screenshots (first is copy, second is paste). |
@CodeKiwi I actually duplicate a selection by Ctrl-C, Ctrl-V, Ctrl-V, pasting over the original. Not sure how common that is. |
This might be fixed with #15976. |
Thanks for your contribution! This issue has been automatically marked as stale because it has not had recent activity. Because the Atom team treats their issues as their backlog, stale issues are closed. If you would like this issue to remain open:
Issues that are labeled as triaged will not be automatically marked as stale. |
Thanks for your contribution! This issue has been automatically marked as stale because it has not had recent activity. Because the Atom team treats their issues as their backlog, stale issues are closed. If you would like this issue to remain open:
Issues that are labeled as triaged will not be automatically marked as stale. |
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks! |
2 similar comments
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks! |
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks! |
When copying a segment of code that starts with a new-line followed by tabbed-in code while "Auto Indent On Paste" is enabled, consecutive pastes will each be an additional tab deeper. I tested this with C++, Java, and JavaScript which makes me believe it is not a problem with the language specs.
Here is an example in the form of an animated gif:
It isn't just comments that this happens with, but it does require the previous line to be selected. Specifically, this happens when the copy-buffer matches a regex like
/^\n\s+[^\s]/
. That is, it starts with a newline, followed by one or more whitespace characters and then a non-whitespace character. And the previous line must be a blank line.The text was updated successfully, but these errors were encountered: