Skip to content

Outdent issue with Typescript #9409

Closed
Closed

Description

@normalser
  • VSCode Version: 1.4.0-insider and 1.3.1
  • OS Version: OSX

Steps to Reproduce:

1 - Highlight

image

2 - Outdent with Cmd + [

Result (first issue):

image

3 - Outdent again with Cmd + [

Result (second issue):
image

Expected behavior:

First outdent:
image

Second outdent:
image

Activity

  1. weinand commented on Jul 17, 2016

    @weinand
    Contributor

    @wallverb I can not reproduce this problem.
    It is possible that this issue is caused by an installed extension. Can you try to run VS Code without extensions? From the command line, execute: code --disable-extensions and try your steps again to see if it reproduces. If you see it is an issue with the extension, please file it against the extension repository itself.

  2. added
    info-needed
    on Jul 17, 2016
  3. normalser commented on Jul 17, 2016

    @normalser
    Author

    Andre Weinand (@weinand) here are the steps to recreate:

    1. mkdir test
    2. code --disable-extensions test
    3. Create file test.ts
    4. Paste this into test.ts
    const data = {
      "typeName": "chart",
          "data": {
            "header": "my title"
          }
    }
    
    
    
    export class Sidebar {
        renderLink() {
            return {
                test: true
            }
        }
    }
    

    5 - Try to outdent:

    image

    If works then proceed to step 6

    6 - Close VSCode
    7 - code --disable-extensions test
    8 - Try to outdent again

    I'm getting the issue from above screenshots

  4. weinand commented on Jul 17, 2016

    @weinand
    Contributor

    @wallverb I can reproduce with your snippet. This issue is independent from TypeScript.

    The snippet has inconsistent indentation: 6 lines seem to use 4 spaces for one indentation level, 3 lines use 2 spaces. Since you are probably using the default editor setting "editor.detectIndentation": true, VS Code determines the tab size to be 4 (you can see this in the editor's status bar at the bottom).

    Since the outdent operation has to move the lines to valid tab positions, the result is unexpected but correct.

    Your expected behaviour would require a tabSize of 2. To achieve this, you will have to use these settings:

    "editor.tabSize": 2,
    "editor.detectIndentation": false
  5. removed
    info-needed
    on Jul 17, 2016
  6. normalser commented on Jul 17, 2016

    @normalser
    Author

    Right, I knew it was related to mix of 2 spaces and 4 spaces tabs - but even that assuming that VSCode detected Spaces: 4 it shouldn't "break" children

    In other words: (assuming Spaces: 4)

    Starting state:
    image

    Current outdent operation results in:

    image

    (notice how children got unaligned)

    Ideal situation would be if VSCode could "fix" the indentation difference and for example create this output:

    image

    ("data" was only moved by 2 spaces left to fit into 4 spaces tab and children got "fixed")

    or at least just move everything by 2 spaces to the left (so `"data" follows the 4 spaces tab) or (what Atom does) - just move everything 4 spaces to the left - without "breaking children"

  7. alexdima commented on Aug 9, 2016

    @alexdima
    Member

    This issue touches on two topics:

    • should outdent "dumbly" remove x spaces from each line -- today it tries to snap code into tab stops.
    • should outdent be a no-op if not all lines have leading whitespace.

    I think both behaviours have pros and cons. i.e. I have a feeling they should be expressed as settings.

  8. added
    feature-request
    on Aug 9, 2016
  9. lewisl9029 commented on Nov 17, 2016

    @lewisl9029

    IMO dumb indentation should be the default, since that's the default behavior for most editors, and is least likely to break existing formatting. Especially in languages like Clojure where partial indents are very prevalent (see #15598).

    That's my 2c, but as long as it's configurable at all as a setting, I can live with it.

  10. added
    typescript
    on Nov 22, 2016
  11. BillDenton commented on Jan 26, 2017

    @BillDenton

    Similar problem in C++ (also C). For example,
    image
    Do outdent:
    image
    Second parameter was aligned, now isn't. A dumb indentation should be default. This would make it work as I expect, i.e. not change the layout. When one of the lines doesn't contain whitespace either stop working or start stripping whitespace (in tab size steps) from the other lines. This is behaviour in SlickEdit, which I find useful occasionally.

  12. added
    bug
    on Jan 31, 2017
  13. alexdima commented on Sep 27, 2017

    @alexdima
    Member

    Setting "editor.useTabStops": false gives the desired behaviour. It has been shipped since quite a while, I forgot to update this issue.

  14. added
    verified
    editor-autoindent
    and removed
    typescript
    on Sep 27, 2017
  15. locked and limited conversation to collaborators on Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugeditor-autoindentfeature-requestverified

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions