Vscode: Auto close parens, brackets, quotes, etc not working when cursor is immediately before comma or semicolon

Created on 20 Jan 2018  路  7Comments  路  Source: microsoft/vscode

  • VSCode Version: Code 1.19.2 (490ef761b76b3f3b3832eff7a588aac891e5fe80, 2018-01-10T15:49:04.682Z)
  • OS Version: Darwin x64 17.3.0
  • Extensions:

Extension|Author (truncated)|Version
---|---|---
vsc-material-theme|Equ|1.2.0
material-icon-theme|PKi|3.2.1
vscode-docker|Pet|0.0.23
code-settings-sync|Sha|2.8.7
npm-intellisense|chr|1.3.0
path-intellisense|chr|1.4.2
vscode-eslint|dba|1.4.4
es7-react-js-snippets|dsz|1.3.1
gitlens|eam|7.5.5
vscode-npm-script|eg2|0.3.3
prettier-vscode|esb|1.1.2
auto-close-tag|for|0.5.5
auto-rename-tag|for|0.0.15
sublime-babel-vscode|jos|0.2.9
graphql-for-vscode|kum|1.8.2
git-indicators|lam|1.2.6
atom-keybindings|ms-|3.0.4
debugger-for-chrome|msj|4.0.0
vscode-icons|rob|7.19.0
colonize|vms|2.2.2
markdown-all-in-one|yzh|1.0.2

(2 theme extensions excluded)


Steps to Reproduce:

  1. type var test = ;
  2. place cursor immediately left of semicolon
  3. type a single quote, left parenthesis, or left bracket
  4. closing character is not inserted - only the typed character appears
  5. expected closing character to be automatically inserted (this functionality exists in Atom)
  6. issue also occurs with commas - test by using prop: , to represent an object, then following steps 2-5.


Reproduces without extensions: Yes

*duplicate editor-autoclosing feature-request

Most helpful comment

@alexandrudima I can appreciate the perspective on the feature's intended usage situations, however I've found need for it in cases outside what you mentioned. For example:

  1. I am writing JSX
  2. I create a new <nav> tag
  3. Thanks to a handy extension, the closing tag is automatically created and the cursor is placed between the opening and closing tags
  4. I move my curser one space to the left, insert a space, then begin typing className=...
  5. At this point, I should have <nav className=|></nav> with my cursor position indicated by the pipe
  6. I want to insert an expression, so I type {. I expect the closing curly bracket to be added and my cursor positioned between the opening and closing curly bracket so I can type my expression. With the current functionality, this does not happen.

I wouldn't consider this to be of extreme importance, it really is just a convenience. I just wanted to provide an actual use case in which this functionality would be valuable. Thanks! :)

All 7 comments

Autoclosing brackets are currently inserted only in some situtations:

  • the cursor is at the end of a line
  • (or) the character after the cursor is a whitespace
  • (or) the character after the cursor is another auto-closing pair

I think the idea is that this feature should kick in mostly when writing new code, as opposed to when editing existing code, hence the simple heuristic above. Better suggestions are welcome!

@alexandrudima I can appreciate the perspective on the feature's intended usage situations, however I've found need for it in cases outside what you mentioned. For example:

  1. I am writing JSX
  2. I create a new <nav> tag
  3. Thanks to a handy extension, the closing tag is automatically created and the cursor is placed between the opening and closing tags
  4. I move my curser one space to the left, insert a space, then begin typing className=...
  5. At this point, I should have <nav className=|></nav> with my cursor position indicated by the pipe
  6. I want to insert an expression, so I type {. I expect the closing curly bracket to be added and my cursor positioned between the opening and closing curly bracket so I can type my expression. With the current functionality, this does not happen.

I wouldn't consider this to be of extreme importance, it really is just a convenience. I just wanted to provide an actual use case in which this functionality would be valuable. Thanks! :)

+1 for this.
There are lots of cases need auto close before other characters.
For example:
I have: list.map(mapper);
Then I want change it to: list.map(mapper).filter(filter);
I would expect the ) show up after I type .filter(

Similar scenario happens a lot when editing existing code.
I would suggest add a config option for this.

/duplicate #35197

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.

Happy Coding!

I believe that's not a duplicate of that issue. That issue only covers curly brackets in JSX tags. JSX was only an example here. From what I've read, this issue is about automatically closing every symbol that encapsulates content, no matter what language. E.g. ", ', <, {, [, (, you get the idea.

You might want to reopen this.

I'm using that issue as a central tracking point for all auto closing enablement related issues as it was the most active of all related issues with the same root cause (auto close is not enabled before non-whitespace). If you look in the actual PR, #52634, you'll see it targets this issue's case as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vsccarl picture vsccarl  路  3Comments

curtw picture curtw  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments

chrisdias picture chrisdias  路  3Comments