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

Indenting multiple lines using Tab fails #2829

Closed
SamVerschueren opened this issue Feb 9, 2016 · 44 comments
Closed

Indenting multiple lines using Tab fails #2829

SamVerschueren opened this issue Feb 9, 2016 · 44 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority verified Verification succeeded
Milestone

Comments

@SamVerschueren
Copy link
Contributor

I wanted to indent multiple lines at once but it failed. This is how it looks like when I select some lines and press Tab. Sometimes it works though, like when creating an untitled file in split screen.

indent

Quite important bug @egamma @jrieken @bpasero

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority labels Feb 9, 2016
@bpasero
Copy link
Member

bpasero commented Feb 9, 2016

@alexandrudima fyi

@philipgiuliani
Copy link

Same here! Cant work with it currently! It also intents completly wrong when i create a newline. (With a tab instead of spaces also...)

@SamVerschueren
Copy link
Contributor Author

It also intents completly wrong when i create a newline. (With a tab instead of spaces also...)

That's something else and was introduced in the previous version as well. If editor.insertSpaces is set to auto it detects the indentation used by the opened file. But if you create a new file, it can't detect the indentation type so it uses spaces instead. Some issues regarding this have been raised already and should be discussed over there. Here it is: #1747

@rhires
Copy link

rhires commented Feb 9, 2016

This looks like Mac OS behavior for the select before the editor knows that the select requires different behavior. It's just not catching that first select. Once the file is in the working files section then the editor has it in memory...this is me speculating, though, and watching what is happening.

@philipgiuliani
Copy link

Can somebody provide a link for VSCode 0.10.6? Its impossible to work on HTML with this Version. Hope to have it fixed soon.

@SamVerschueren
What i mean is the following. (Extension .jsx, file is not empty, it has 70 lines)
This behaviour was definetly not present before.

Steps to reproduce:

  1. .jsx file (maybe also other ones)
  2. Indent somewhere in a function, move the cursor to another line and save the file (be sure to have "remove leading whitespace" option enabled)
  3. Go back to that line and press TAB.

indentation

@SamVerschueren
Copy link
Contributor Author

@philipgiuliani Ok, that's definitely something else. Create a new issue for that one if you don't mind as it's not the same as this one and then they can separately being tracked by the team.

@philipgiuliani
Copy link

@SamVerschueren Thank you! Done in the following issue #2845.

@bpasero
Copy link
Member

bpasero commented Feb 9, 2016

Previous releases are at https://github.com/Microsoft/vscode/wiki/Previous-Releases

@nchammas
Copy link

nchammas commented Feb 9, 2016

Having a similar issue with SQL files if I highlight some lines and try to indent them with tab.

screen recording 2016-02-09 at 03 27 pm

This one is strange because, in addition to killing all the text, Command + Z refuses to undo the action!

If I manually indent the first line with 4 spaces and highlight the rest, hitting tab works as expected.

@alexdima
Copy link
Member

@SamVerschueren @philipgiuliani @nchammas I am sorry, this looks horrible.

I cannot reproduce on a vanilla (no extensions) 0.10.8 on Windows.
tab-sql

tab-text

I will try shortly on the mac

@SamVerschueren
Copy link
Contributor Author

Indeed, might be related to Mac.

@alexdima
Copy link
Member

@SamVerschueren Do you have any extensions installed that might hijack the tab key? i.e. just to be sure the built-in command executes, can you please add the following to the end of your keybindings.json:

{ "key": "tab", "command": "tab", "when": "editorTextFocus && !editorTabMovesFocus" }

@SamVerschueren
Copy link
Contributor Author

Added that but still the same behaviour.

Switched to the insider build and removed all the extensions I had installed over there (just to make sure) but still the same.

@alexdima
Copy link
Member

I still cannot reproduce. Can you think of anything else I might be doing differently? Do you have other settings for VSCode or maybe a different keyboard layout, etc...

Here I am trying on a mac:

All I do is select some text, press Tab a few times and undo (Cmd+Z)

I have just downloaded 0.10.8 from the website on a new mac install:

screen shot 2016-02-10 at 12 00 45

tab-jsx

tab-txt

tab-sql

@weinand @joaomoreno Can you please also try to reproduce this?

@SamVerschueren
Copy link
Contributor Author

This is odd.

I installed a new fresh version of the latest insider build. Removed my Application Support/Code - Insiders directory to make sure I don't have any setting specified. Still the same behaviour.

I have a U.S. keyboard layout.

screen shot 2016-02-10 at 12 11 44


@alexandrudima In your second example (the untitled file), can you type your text (as it is now), save it as test.txt or something and try it again?

indent

@alexdima
Copy link
Member

Ok, here I am trying again with an untitled file that then I save on top of an existing file.

tab-txt-again4

Do you maybe press Tab while in the OS menus? Do you maybe have any errors in the console (F1 > Toggle Developer Tools)? Does this repro when pressing Cmd+] which is an alternative binding for indent lines?

Here is the OSX version I'm trying on, maybe this makes a difference?
screen shot 2016-02-10 at 12 23 13

@SamVerschueren
Copy link
Contributor Author

Do you maybe press Tab while in the OS menus?

No

Do you maybe have any errors in the console

No

Does this repro when pressing Cmd+] which is an alternative binding for indent lines?

No, can't reproduce with this keybinding which is odd.


This is how it always acts like that.

  1. Open the project and open that test.txt file
  2. Close VS Code entirely
  3. Open VS Code which will open test.txt automatically
  4. Select all the lines and press Tab

My OS X is one patch version higher.

screen shot 2016-02-10 at 12 35 34

@philipgiuliani
Copy link

I also have it on El Capitan 10.11.3

settings.json

{
    "files.trimTrailingWhitespace": true,
    "editor.wrappingIndent": "indent",
    "editor.renderWhitespace": true
}

@sijad
Copy link
Contributor

sijad commented Feb 10, 2016

I also have it, this is my setting.json:

{
  "editor.insertSpaces": true,
  "editor.tabSize": 2,
  "search.exclude": {
    "**/dist": true
  },
  "files.trimTrailingWhitespace": true,
  "files.insertFinalNewline": true,
  "editor.fontFamily": "hack",
  "editor.fontSize": 12,
  "editor.renderWhitespace": true
}

on El Capitan 10.11.3

@alexdima
Copy link
Member

Quick update: just updated to El Capitan 10.11.3 and I can now immediately reproduce even with the default settings

@SamVerschueren
Copy link
Contributor Author

\O/ JEEJ! :)

@egamma
Copy link
Member

egamma commented Feb 10, 2016

@philipgiuliani

Can somebody provide a link for VSCode 0.10.6?

Previous releases are available from https://github.com/Microsoft/vscode/wiki/Previous-Releases

@alexdima
Copy link
Member

@SamVerschueren @philipgiuliani @nchammas @sijad

Can you please try the following workarounds and let us know if they work.

Possible workaround 1

Edit settings.json to enable auto save with a delay <= 1000:

    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 1000

Possible workaround 2

Have a "dirty" file permanently open. (i.e. open a new untitled file, make a change in it) and then go about editing other files -- without any need to enable auto save as above.

Explanation

Took a few hours to track down, the problem surfaces so far only on OS X El Capitan 10.11.3 and only on an edit that causes the first file to become "dirty": (i.e. on the edit that brings VS Code from having 0 unsaved files to 1 unsaved file).

The underlying problem is we are updating the OS window to mark the VS Code window as containing a dirty file (icon gets greyed out) synchronously, in a model change listener, while the keydown event is still being handled. This causes e.preventDefault() to malfunction, producing a follow up unexpected input event, while still handling the original keydown event. We then react to the input event and begin applying edits to the model. Thus, the model gets edits applied while it is applying edits, which is unexpected (causing undo to malfunction).

Filed issue against Electron in electron/electron#4438 and we need to revisit all our code paths where we use remote during handling an event.

@nchammas
Copy link

@alexandrudima - Workaround 1 works for me. 👍

@joeskeen
Copy link
Contributor

I found another workaround (since I don't like auto-save):

  1. insert a space
  2. delete the space
  3. (don't save)

Now you can tab/shift-tab to your heart's delight. As long as the file is already 'dirty', the bug won't happen.

If you do happen to accidentally clobber your code with tab/shift-tab, you can right-click the file in the Working Files view and select "Revert file".

This is similar to Possible Workaround 2 above, only you don't have to have an extra dirty file open all the time.

@PeterAronZentai
Copy link

@alexandrudima thanks! workaround 2 was a real lifesaver. Small addition that the error exists on OS X 10.11.1 as well.

@ElChupacabra26
Copy link

I'd also like to add that I'm seeing this behavior in OS X 10.10.5 (Yosemite)

@brunnopleffken
Copy link
Contributor

I'm also experiencing this behavior when pressing SHIFT+TAB.
All the selected block of code is deleted and CMD+Z (undo) doesn't work at all.

OS X El Capitan 10.11.3
VS Code 0.10.8-insider

@philipgiuliani
Copy link

@brunnopleffken haha "SHIT + TAB" 😆

@weinand
Copy link
Contributor

weinand commented Feb 17, 2016

@alexandrudima I've verified fix for the insider's build.

@joaomoreno
Copy link
Member

@alexandrudima looks great for stable too

@brunnopleffken
Copy link
Contributor

@philipgiuliani Oops! Mistyping an issue may cause situations like this, HAHAHAHA

@egamma egamma changed the title [0.10.8] What's wrong with the indentation? [0.10.8] Indenting multiple lines using Tab fails Feb 17, 2016
@egamma egamma changed the title [0.10.8] Indenting multiple lines using Tab fails Indenting multiple lines using Tab fails Feb 17, 2016
@yo1dog
Copy link

yo1dog commented Feb 18, 2016

Just want to say thanks for the workarounds and the fixed update today. :)

@ElChupacabra26
Copy link

👍 +1 to that

@SamVerschueren
Copy link
Contributor Author

Thanks @alexandrudima . Appreciate the effort!

@priyank2005
Copy link

Thanks for fixing this

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 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 important Issue identified as high-priority verified Verification succeeded
Projects
None yet
Development

No branches or pull requests