Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Auto indent on paste behaves oddly with already indented lines. #5473

Closed

Description

@NatalieWolfe

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:
autoindent-2

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.

Activity

  1. winstliu commented on Feb 10, 2015

    @winstliu
    Contributor

    What version of Atom is this on?

    /cc @maxbrunsfeld

  2. NatalieWolfe commented on Feb 10, 2015

    @NatalieWolfe
    Author

    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.

  3. self-assigned this
    on Feb 10, 2015
  4. izuzak commented on Feb 13, 2015

    @izuzak
    Contributor

    @NatalieWolfe I'm having trouble reproducing this in the latest version of Atom:

    $ atom -v
    0.180.0-2dac7fd
    

    Here's what I'm doing:

    paste

    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 (cmd+.)? Also, can you record the gif so that includes the point at which you select and copy text into the clipboard for the first time (it's not shown in the gif above)?

    Atom should update to the latest version on its own, but you can download the latest version here as well:

    https://github.com/atom/atom/releases/latest

  5. NatalieWolfe commented on Feb 13, 2015

    @NatalieWolfe
    Author

    @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.

    autoindent-3

    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.

  6. NatalieWolfe commented on Feb 13, 2015

    @NatalieWolfe
    Author

    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).

  7. izuzak commented on Feb 13, 2015

    @izuzak
    Contributor

    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.

  8. karai17 commented on Apr 30, 2015

    @karai17

    I am running the current Atom (194) on Windows 7 and this issue persists.

  9. muppetjones commented on May 19, 2015

    @muppetjones

    There are many indentation problems, and I'm trying to link all of them together in a single issue: here

  10. jesseleite commented on Sep 1, 2015

    @jesseleite

    I'm finding that Auto Indent works differently than Auto Indent On Paste setting in Atom. There's a consistency issue between the two...

    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 Auto Indent On Paste is doing something, but it's not doing it correctly. However, if I now run Auto Indent from the Edit > Lines menu, I get this:

        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 Auto Indent fine, but Auto Indent On Paste seems useless sometimes.

    (For the record, I'm on Yosemite with Atom 1.0.9 in --safe mode.)

  11. jesseleite commented on Sep 1, 2015

    @jesseleite

    ...Oh I see what's going on here. Let me follow up on my last comment.

    Auto Indent On Paste is trying to auto-indent the block as a whole, based on first line's indentation:
    example1

    Whereas PHPStorm is also fixing indentation within the block, making sure each line auto-indents correctly:
    example2

    IMHO, maybe there should be more consistency between manually running Auto Indent, and Auto Indent On Paste, since running Auto Indent manually is smart enough to fix the mess.

    Thoughts?

  12. 9 remaining items

  13. markiragoldberg commented on Jun 27, 2017

    @markiragoldberg

    Thanks @patstew, your work made Atom much more usable for me.

  14. clusteratlas commented on Sep 5, 2017

    @clusteratlas

    This is fucking awesome, thank you very much.

  15. CodeKiwi commented on Sep 6, 2017

    @CodeKiwi

    @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).

    screen shot 2017-09-06 at 7 49 42 am

    screen shot 2017-09-06 at 7 49 50 am

  16. lennartq commented on Oct 25, 2017

    @lennartq

    @CodeKiwi I actually duplicate a selection by Ctrl-C, Ctrl-V, Ctrl-V, pasting over the original. Not sure how common that is.

  17. TimvdLippe commented on Oct 29, 2017

    @TimvdLippe
    Contributor

    This might be fixed with #15976.

  18. stale commented on Oct 29, 2018

    @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:

    1. Verify that you can still reproduce the issue in the latest version of Atom
    2. Comment that the issue is still reproducible and include:
      • What version of Atom you reproduced the issue on
      • What OS and version you reproduced the issue on
      • What steps you followed to reproduce the issue

    Issues that are labeled as triaged will not be automatically marked as stale.

  19. added and removed on Oct 29, 2018
  20. stale commented on Oct 29, 2019

    @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:

    1. Verify that you can still reproduce the issue in the latest version of Atom
    2. Comment that the issue is still reproducible and include:
      • What version of Atom you reproduced the issue on
      • What OS and version you reproduced the issue on
      • What steps you followed to reproduce the issue

    Issues that are labeled as triaged will not be automatically marked as stale.

  21. lock commented on May 20, 2020

    @lock

    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!

  22. lock commented on May 20, 2020

    @lock

    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!

  23. lock commented on May 20, 2020

    @lock

    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!

  24. locked as resolved and limited conversation to collaborators on May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions