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

Add padding when pressing space between a pair of curly braces #22583

Open
noinkling opened this issue Mar 14, 2017 · 2 comments
Open

Add padding when pressing space between a pair of curly braces #22583

noinkling opened this issue Mar 14, 2017 · 2 comments
Labels
editor-autoclosing Editor automatic closing of parens / brackets / etc. feature-request Request for new features or functionality
Milestone

Comments

@noinkling
Copy link

noinkling commented Mar 14, 2017

When I type { to create a pair of curly braces:

{}

...and then when I press space, I would like 2 spaces to be inserted with the cursor in the middle:

{ | }
  ^ cursor

Currently it just inserts a single space, so getting the same result requires pressing space twice then the back arrow once. Or otherwise setting:

"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true
// or "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true

...then formatting the line once there's already stuff inside it.

I believe pressing space between a pair of brackets with nothing between them ({}) is more-or-less an unambiguous signal (in pretty much any language) that the user intends to have a padding space at both ends. It's also very similar to the already-covered case where someone instead presses enter to produce:

{
  | <- cursor
}

In Sublime Text I was able to add the functionality myself using a keybinding that looked (in their format) like:

{ "keys": ["space"], "command": "insert_snippet", "args": {"contents": " $0 "}, "context":
  [
    { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
    { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
    { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
  ]
}

...but in VS Code there doesn't seem to be enough functionality available to add a keybinding like this - I can insert a snippet but can't see anything that would allow me to limit the context to the inside of a pair of brackets.

If someone points me to the place in the codebase where the similar behavior for pressing "enter" is defined, I might be able to open a PR myself.

@weinand weinand added the feature-request Request for new features or functionality label Mar 14, 2017
@alexdima alexdima added this to the Backlog milestone Mar 28, 2017
@alexdima alexdima removed their assignment Mar 28, 2017
@alexdima alexdima added the editor-input Editor text input label Mar 28, 2017
@AiryShift
Copy link
Contributor

I've looked around the codebase but have been unable to find the relevant locations. In the meantime, I made this extension which should do what you've described.

@noinkling
Copy link
Author

noinkling commented Nov 12, 2017

@AiryShift Big thanks for throwing that together, I like the name 😄 I did find a bug where it causes the undo command to get stuck in a loop, hopefully that isn't too hard to fix.

As far as the request goes, I should probably add that it could be applied to square brackets and parens as well (obviously), it's just that curly braces seem to be the most common use case.

Edit: update in case anyone else is reading this; the undo bug in the above extension was fixed, and support added for the other types of braces. Thanks again @AiryShift 👍

@alexdima alexdima added editor-autoclosing Editor automatic closing of parens / brackets / etc. and removed editor-input Editor text input labels Nov 13, 2017
@alexdima alexdima changed the title Feature request: add padding when pressing space between a pair of curly braces Add padding when pressing space between a pair of curly braces Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-autoclosing Editor automatic closing of parens / brackets / etc. feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants