Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outdent issue with Typescript #9409

Closed
normalser opened this issue Jul 17, 2016 · 8 comments
Closed

Outdent issue with Typescript #9409

normalser opened this issue Jul 17, 2016 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality verified Verification succeeded

Comments

@normalser
Copy link

  • 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

@weinand
Copy link
Contributor

weinand commented Jul 17, 2016

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

@weinand weinand added the info-needed Issue requires more information from poster label Jul 17, 2016
@normalser
Copy link
Author

@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

@weinand
Copy link
Contributor

weinand commented Jul 17, 2016

@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

@weinand weinand removed the info-needed Issue requires more information from poster label Jul 17, 2016
@normalser
Copy link
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"

@alexdima
Copy link
Member

alexdima commented Aug 9, 2016

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.

@alexdima alexdima added the feature-request Request for new features or functionality label Aug 9, 2016
@alexdima alexdima added this to the Backlog milestone Aug 9, 2016
@lewisl9029
Copy link

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.

@mjbvz mjbvz added the typescript Typescript support issues label Nov 22, 2016
@BillDenton
Copy link

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.

@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Jan 31, 2017
@alexdima
Copy link
Member

alexdima commented Sep 27, 2017

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

@alexdima alexdima modified the milestones: Backlog, September 2017 Sep 27, 2017
@ramya-rao-a ramya-rao-a added verified Verification succeeded editor-autoindent Editor auto indentation issues and removed typescript Typescript support issues labels Sep 27, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

8 participants