Skip to content

Wrong auto-indentation in typescript #209802

Closed

Description

@rzvc

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.88.0
  • OS Version: Ubuntu 22.04

Steps to Reproduce:

if (true)<enter>
	{<enter>
	}

This seems to happen on for and while as well. In other languages auto-indentation doesn't happen after the first <enter> in the example. While it could be good as a feature, it would be great if on typing the opening bracket, it would automatically un-indent. Also, it seems like the kind of thing that needs a toggle, because it can backfire in multiple ways.

Another thing that I noticed was that the auto-indentation happens even if the if line is commented out.

// if (true)<enter>
	|<cursor ends up here>

This was not a problem in the previous version.

Activity

  1. StevenJohnston commented on Apr 11, 2024

    @StevenJohnston

    I too have this issue

  2. AndrewStovell commented on Apr 14, 2024

    @AndrewStovell

    +1 to also having this issue. Can confirm, If, Else If, For, While, and Arrow Functions affected. Functions & Switches are fine.
    Have tried commenting out settings.json, and issue persists.

    Version: 1.88.1 (user setup)
    Commit: e170252
    Date: 2024-04-10T17:41:02.734Z
    Electron: 28.2.8
    ElectronBuildId: 27744544
    Chromium: 120.0.6099.291
    Node.js: 18.18.2
    V8: 12.0.267.19-electron.0
    OS: Windows_NT x64 10.0.22631

  3. TheWyo commented on Apr 22, 2024

    @TheWyo

    Seems to be a re-occurrence of #30933 from quite some time ago.

  4. 1564047446 commented on Apr 30, 2024

    @1564047446

    yeah, the latest version must auto error. emmmm, how long fix the bug

  5. Jemt commented on May 5, 2024

    @Jemt

    I wonder why this bug report does not have a billion upvotes. I have the same problem, and it makes it a pain to write code. I constantly have to fix it manually. I tried disabling all my extensions and clear both User settings (JSON) and Workspace settings (JSON), but to no eval.

    This is what I experience in JS files:

    image

    Pressing ENTER after control flows such as if or for indents the cursor like shown above, where it previously placed the cursor right below the if part.

    In the example below I pressed ENTER after the function() declaration on line 5 which caused incorrect indentation in the opposite direction:

    image

    Previously it placed the cursor right below the [] part.

    Things seems to work fine for PHP files.

    Tested with VSCode 1.89.0 (commit b58957e) on macOS 12.7.2.

    "About Visual Studio Code":
    Version: 1.89.0
    Commit: b58957e
    Date: 2024-05-01T02:10:10.196Z
    Electron: 28.2.8
    ElectronBuildId: 27744544
    Chromium: 120.0.6099.291
    Node.js: 18.18.2
    V8: 12.0.267.19-electron.0
    OS: Darwin x64 21.6.0

  6. FlowIT-JIT commented on May 6, 2024

    @FlowIT-JIT

    Probably a duplicate of #209805
    Although I'm not sure this covers the issue with the forEach(..) construct.
    The problems mentioned by Jimmy Thomsen (@Jemt) also applies to TypeScript. This is completely unacceptable.

  7. FlowIT-JIT commented on May 6, 2024

    @FlowIT-JIT

    Switching Auto indent to "advanced" makes VSCode usable again:

    image

    But it's beyond me that 1.88 even shipped with these changes. Completely destroyed the editing experience.

  8. FlowIT-JIT commented on May 6, 2024

    @FlowIT-JIT

    This is the behaviour with "Auto indent" set to Full:

    VSCodeindentationbugs-ezgif com-video-to-gif-converter

    I constantly have to fix the code.

  9. ssigwart commented on May 11, 2024

    @ssigwart
    Contributor

    For those that don't like the new behavior, I created the ssigwart.javascript-typescript-language-configuration extension that will remove the auto-indenting after if, for, and while in JavaScript and Typescript.

  10. aiday-mar commented on May 13, 2024

    @aiday-mar
    Collaborator

    Hi everyone thank you for expressing your concern. This change has come in as a result of the following issue with 43 upvotes (#43244) which precisely asked for indentation to be added after a braceless if/for/while statement. I will explore the idea of adding indentation by default, and then removing it when { is typed.

  11. 12 remaining items

  12. added
    unreleased
    on Jun 20, 2024
  13. photonstorm commented on Jun 20, 2024

    @photonstorm

    So happy to see this fixed. How do we easily track when it enters a live release version? As I'm pinned to v1.87 and don't want to turn automatic updates on again until I know this has landed.

  14. aiday-mar commented on Jun 20, 2024

    @aiday-mar
    Collaborator

    The update that has been merged today will be in tomorrow's Insiders release and in next month's stable release :). Next month's stable release should come out around beginning of July

  15. added
    insiders-released
    and removed
    unreleased
    on Jun 21, 2024
  16. aiday-mar commented on Jun 24, 2024

    @aiday-mar
    Collaborator

    To verify:

    • Open a TypeScript or JavaScript file
    • Type if(<some code>) in the file
    • Type Enter, verify the next line is indented
    • Type an opening curly brace {, verify a second closing curly brace is added and we have:
    if(<some code>)
    {}
    • Press Enter from within the curly braces, verify we have:
    if(<some code>)
    {
    ....
    }

    Here the dots represent the spaces.

  17. FlowIT-JIT commented on Jun 24, 2024

    @FlowIT-JIT

    Here the dots represent the spaces.

    Aiday Marlen Kyzy (@aiday-mar) That will be a TAB if VSCode is configured to use those instead, right ?

  18. aiday-mar commented on Jun 24, 2024

    @aiday-mar
    Collaborator

    Hi FlowIT-JIT yes these should be tabs if you configured tabs for the file

  19. added
    bug
    and removed
    verification-needed
    on Jun 24, 2024
  20. rzvc commented on Jul 23, 2024

    @rzvc
    ContributorAuthor

    Aiday Marlen Kyzy (@aiday-mar), thank you. It works when typing, but still presents the issue when pasting.

    I have created a new issue for that scenario: #223308.

  21. locked and limited conversation to collaborators on Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugeditor-autoindentinsiders-releasedjavascripttypescriptverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions