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 not correct when moving lines up or down #10524

Closed

Description

@brandonk3nt

When you move a group of selected lines up or down, Atom auto indents them to where it thinks they should fit in the code and it is not always correct. It should have the option to disable this flavor of auto indent.

Activity

  1. amytruong commented on Jan 25, 2016

    @amytruong

    If you go into Settings View and scroll down to Editor Settings, we do have an option to turn off Auto Indent and Auto Indent on Paste. Let us know if that solves your problem. 😬 crosses fingers

  2. benogle commented on Jan 25, 2016

    @benogle
    Contributor

    Also, can you be more specific about your atom version and what languages you're having problems with?

  3. brandonk3nt commented on Jan 25, 2016

    @brandonk3nt
    Author

    Hey Amy,

    Thanks for responding, that was quick! So I tried those settings earlier
    and they don't affect the auto indent reformatting when using the hotkeys
    (Ctrl + Option + up/down). Even with those two options turned off it still
    will reformat indentation and not always for the better. It's particularly
    noticeable when you highlight a block of code that has specific indentation
    and move it up or down. I love Atom and this is my only issue with it.
    Thanks for your help!

    Brandon Kent | Software Engineer
    www.brandonk3nt.com
    Email: [email protected]
    Cell: 480.788.1301

    "A journey of a thousand miles begins with a single step."
    On Jan 25, 2016 2:02 PM, "Amy Truong" [email protected] wrote:

    If you go into Settings View and scroll down to Editor Settings, we do
    have an option to turn off Auto Indent and Auto Indent on Paste. Let us
    know if that solves your problem. [image: 😬] crosses fingers

    —
    Reply to this email directly or view it on GitHub
    #10524 (comment).

  4. brandonk3nt commented on Jan 25, 2016

    @brandonk3nt
    Author

    ​Hey Ben,

    Thanks for reaching out- I just responded to Amy but here's some more
    details that will hopefully help to reproduce the bug. I am on a Mac
    (running El Capitan) and running Atom v1.4.0. I am code in CoffeeScript,
    which uses indentation vs punctuation to define blocks of code (like
    Python). The bug occurs when using the hotkeys to move selections up or
    down (Ctrl + Command + up/down-arrow). ​It is particularly noticeable when
    you highlight a chunk of code >5 lines which has specific indentation, and
    move it up or down through other sections of code. Hope this helps and
    please let me know if I can do more to help, thanks!

    Brandon Kent | Software Engineer
    E: [email protected] [email protected]
    T: 480.788.1301
    brandonk3nt.com http://www.brandonk3nt.com/

    "If there's one attribute that everyone could adopt from the skateboarding
    community, it's to have a desire to learn something new- to try, and fall,
    and get up again- and repeat that process a thousand times until you
    eventually get it right."

    On Mon, Jan 25, 2016 at 2:09 PM, Ben Ogle [email protected] wrote:

    Also, can you be more specific about your atom version and what languages
    you're having problems with?

    —
    Reply to this email directly or view it on GitHub
    #10524 (comment).

  5. benogle commented on Jan 25, 2016

    @benogle
    Contributor

    Noted, yeah, it's really bad at auto indenting chunks for whitespace delimited languages.

  6. tomek-he-him commented on Feb 15, 2016

    @tomek-he-him

    Hi, I’m also having trouble with this feature when coding in Elm – another language with significant whitespace.

    As @amytruong suggested:

    • I tried switching off Auto Indent. That did the job, but it also turned off indenting every new line. The latter is a super useful feature – I can’t imagine coding without that.
    • I tried switching off Auto Indent on Paste. Unfortunately, that didn’t work.
  7. maackle commented on Feb 17, 2016

    @maackle

    I just ran into this problem too. Here's a simple case in Python:

    def foo():
        if True:
            print("fizz")
        print("buzz")

    If I highlight lines 2-4 and move them up or down, print("buzz") gets indented to the same level as print("fizz"), totally changing the program.

  8. radiac commented on Feb 29, 2016

    @radiac

    I have also just had the same python issue. This really should be an option, and probably be off by default, at least for languages which have significant whitespace. There is further discussion of this issue on the original PR (#9104), with a custom command that solves it for me.

  9. code-tree commented on Mar 1, 2016

    @code-tree

    I'm finding this feature addition is almost always actually a hindrance to me. When I move code, it is extremely important it stays as it is (especially in Python, where indentation affects everything). After moving blocks of code it takes me a while to check if anything has changed, and to correct the indentation, where as a simple tab (or shift tab) would normally fix things after a move.

    But I do appreciate the effort in trying to add a new feature, and I think it could be useful, but only (in my personal opinion) if no indentation changes within the selected lines

    i.e. If the selected (multi-line) code is auto-indented less/more, indent it all equally (not just some lines of it).

  10. mgruner commented on Apr 12, 2016

    @mgruner

    +1

  11. Krknv commented on May 30, 2016

    @Krknv

    Just used Ctrl+Command+up/down and cmd + z

    may-30-2016 10-31-01

  12. mxmlnkn commented on Jun 7, 2016

    @mxmlnkn

    @RsD0p9BK Doesn't work for me, also not very high usability.
    As for reproduction:
    I have the following plain text (!) test.txt

    hi
        there
    me
    

    When trying to move the line with there up using Ctrl+Up the indentation gets lost resulting in

    there
    hi
    me
    

    Using Atom 1.8.0 on Debian.

  13. Krknv commented on Jun 8, 2016

    @Krknv

    @mxmlnkn Try to add empty string at the end of file (Eight on my picture)

  14. adamreisnz commented on Jun 26, 2016

    @adamreisnz

    Here's another way to reproduce weird indentation behaviour when moving lines of code up:

    1. Create a block comment like so with two lines of code underneath it:
    /**
     * Dependencies
     */
    let moment = require('moment');
    let mongoose = require('mongoose');
    1. Try to move the last line up. You will end up with:
    /**
     * Dependencies
     */
     let mongoose = require('mongoose');
    let moment = require('moment');

    Notice the one space added indentation, and what's even stranger, the added space actually gets selected.

    Presumably to do with the fact that the comment block has a one-space "indentation". In this case the space is not really an indentation though, and the editor should "know" that my indentation is actually set to two spaces, not one, so it shouldn't interpret the single space as an indentation.

    Demo:

    ss

    This is with Atom 1.10.0-dev-e5a3c9e, and this joins several other comment block/indentation related issues like:

    #11995
    #5362
    #7256 (comment)

    @benogle does this issue still require more information or do you have enough to start looking into it? I think it's probably a good idea if all of these related issues were tackled at the same time. It seems they are all at least somewhat related.

    Let me know if you need more information or if you require me to do some testing.

  15. 5 remaining items

  16. chris-martin commented on Feb 3, 2017

    @chris-martin

    The relevant functions are here:

    moveLineUp: ->

    Could we work around this with a plugin to add alternative versions of those functions?

  17. adamreisnz commented on Feb 3, 2017

    @adamreisnz

    If it were written in normal javascript/ES6+ I'd happily take a look, but alas, I'm allergic to Coffeescript ;)

  18. LydiaF commented on Apr 26, 2017

    @LydiaF

    Hi there,

    I am using YAML and I have this problem. It works as I would like it when Auto Indent is false in Editor Setting, but I would much prefer to keep that setting turned on.

    moving lines

    It would make a huge difference to me if there was a setting to turn this behaviour off!

    Thank you :)

  19. oneschilling commented on Aug 21, 2017

    @oneschilling

    I am having the same issue. An option to turn auto indentation off for moving lines up and down would be great.

  20. corysimmons commented on Sep 21, 2017

    @corysimmons

    Atom team: Why use auto-indent after the move? Auto-indent is always error prone in every editor.

    • Just store all the selected characters (like whitespace) in tmp memory.
    • If their is no selection, just store the entire line in tmp memory.

    What's the technical hold up on this?

    For posterity, this has been a really annoying problem with Atom since Atom was made. Tons of issues. Some PRs that don't actually fix the problem. etc.

  21. Signum commented on Sep 21, 2017

    @Signum

    Well, any other editor I have seen so far (that supports moving of lines) handles that well. Only Atom tries to auto-indent during a move. So that's just unexpected behavior.

    Moving that way makes it easier visible in my opinion. You move something until it fits perfectly. You do not have to trim or add empty lines before or after a block. It's WYSIWYG.

    But if it's terribly hard to disable auto-indent while moving lines then perhaps it's really not worth fixing it.

  22. DiThi commented on Nov 23, 2017

    @DiThi

    It's ironic that it's written in Coffee Script. It destroys the indentation on Coffee Script!!

    I'm OK with it moving the whole block left or right. But moving individual lines of code makes it USELESS for most cases.

    Extremely simple case:

        if true
            1
        if false
            2

    turns into

        if true
            1
            if false
                2

    And the worst part is that sometimes it happened to us without noticing, introducing bugs.

  23. gardwired commented on Mar 12, 2018

    @gardwired

    please fix. autoindent shouldn't pertain to moves.

  24. critcha commented on Jan 5, 2019

    @critcha

    Dear Atom developers: I believe you can fix this unexpected behavior deleting the following line from the definition of movelineup and movelinedown in TextEditor.js
    if (this.shouldAutoIndent()) this.autoIndentSelectedRows()

    Please try to fix this, as I find this issue to be a huge problem when I'm using Atom to write most kinds of code.

  25. jemisjoky commented on Apr 1, 2019

    @jemisjoky

    I've used Atom for a couple months and while the overall layout and feel is very nice (the Git integration is especially lovely), this issue with auto-indentation has already caused frustrating bugs in my code on three separate occasions (all in Python). Two of those bugs were caused by the addition of single spaces in large blocks of code (as described by @adamreisnz), which is very difficult to spot visually.

    While I hugely appreciate that Atom is open source, I'll be going back to Sublime after this on account of text movement being a stable operation there :(

  26. stale commented on Mar 31, 2020

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

  27. cornelius-dol commented on Sep 24, 2022

    @cornelius-dol

    Yes, I can still reproduce in the latest version (1.16.0), and it's INCREDIBLY annoying. It also, badly auto-indents when I edit an existing line, behavior which drives me completely bonkers.

    What I would really like is the option to auto-indent to current indentation level on insertion of a new line ONLY. Just that. Nothing else. Nothing fancy. Just maintain the current indentation upon line insertion. While I know I can turn off indentation altogether, the indentation on insertion of a new line is incredibly useful. Essentially, you've borked the most useful auto-indent behavior by trying to make it too fancy.

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