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

Better behavior of the autoClosingBrackets-Feature for quotation marks #7092

Closed
lafe opened this issue Jun 1, 2016 · 6 comments
Closed

Better behavior of the autoClosingBrackets-Feature for quotation marks #7092

lafe opened this issue Jun 1, 2016 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoclosing Editor automatic closing of parens / brackets / etc.
Milestone

Comments

@lafe
Copy link

lafe commented Jun 1, 2016

  • VSCode Version: 1.2.0-insider
  • OS Version: Windows Server 2008 R2

As discussed in issue #327, the autoClosingBrackets option has some edge cases where it does not speed up typing but actually increases the work necessary. One of these cases is when I try to replace quotation marks as start and end character of strings.

Steps to Reproduce:

  1. Open a TypeScript file
  2. Select a single quoation mark (')
  3. Trying to replace it with double quotation marks (") leads to a a single quotation mark wrapped in double quotation marks (" ' "; I added the spaces to make it more readable)

The same issue occurs when I use the grave accent to replace double quotation marks. It would be great if VS Code could detect the intention and overwrite the selected character or replace the start and end chartacter of the string (e.g. 'Hello World' becomes "Hello World" or Hello World based on the new character).

@alexdima alexdima assigned joaomoreno and unassigned alexdima Aug 9, 2016
@joaomoreno joaomoreno added the editor-bracket-matching Editor brace matching label Aug 10, 2016
@joaomoreno joaomoreno added this to the Backlog milestone Aug 10, 2016
@joaomoreno joaomoreno added the bug Issue identified by VS Code Team member as probable bug label Aug 17, 2016
@JonMarbach
Copy link

JonMarbach commented Nov 4, 2016

This issue has impacted me as well (version 1.4.0 Win8). I was giving a demo and using VS Code "as a very helpful editor" when I made the following mistake in some html:

onclick="alert("Hi");"

When I highlighted the " in front of Hi and typed ' I got ' " ' (Like the OP, spaces added for clarity), which I then had to delete. Ok, but things get wackier...

The cursor is placed after the ", so I hit backspace twice to delete it and the preceding '. But this auto-deletes the trailing ' after the cursor (try it out to see what I mean.) So I have to type the single quote all over again. That gets us to this point:

onclick="alert('Hi");"

OK, well, obviously if I select the " after Hi and type ' I'll get the same behavior, so let's try something different... If I delete the " and type ' after the Hi then I get a pair of single quotes:

onclick="alert('Hi'');"

That's not what I wanted, so I hit backspace, but that deletes the pair of 's, which is also not what I wanted... So finally, I type ' again, which gives me ' ' and I can hit the Delete key (not backspace) and then I've finally corrected this simple typo.

This description might be hard to follow but if you start out with an html file, create my original typo in an html tag and then try different ways of fixing it, you'll see what I mean.

Finally, I've read about turning off autoClosingBrackets, but I like the auto closing of the brackets OK, just not of the quotes.

[Side suggestion - Alphabetize the contents of the default settings file...? At least within a group like editor.*?]

@JohnLudlow
Copy link

I've seen a similar issue when, for whatever reason, I end up with mismatched quotes. If a line has quotes at the start, but the end is missing a quote, I go to the end of the line and type ". Unfortunately, this adds two quotes like this "".

I get the same issue with brackets, though that's not nearly so bad.

@jkyeung
Copy link

jkyeung commented Sep 22, 2017

I have a lot of empathy for the folks who have posted and upvoted in this thread. But I'm not sure it's possible to get this exactly right in all cases. After all, there are certainly plenty of times when a programmer might legitimately want the existing behavior (e.g. to convert a naked single-quote character into a double-quoted string of length one whose content happens to be the original single-quote character).

Better detection of intention (assuming that's even possible) might come down to significantly more sophisticated language parsing, and that might be difficult to implement and could easily add a lot of overhead (read: make the editor feel more sluggish).

So a better angle of attack might be to suss out what different kinds of behavior would be desirable and move some of those behaviors to other settings or other keymappable actions. Maybe converting existing brackets to different brackets could be its own thing, for example, separate from adding new surrounding brackets. Potentially another key combo to learn, but less chance the editor will do something against the user's wishes.

@alexdima alexdima added editor-autoclosing Editor automatic closing of parens / brackets / etc. and removed editor-bracket-matching Editor brace matching labels Oct 20, 2017
@joaomoreno joaomoreno assigned rebornix and unassigned joaomoreno Nov 23, 2017
@payonel
Copy link

payonel commented Aug 26, 2018

just please leave me the option to disable ALL AUTO closing of every kind. I have never liked it in any editor. If the editor shows a closing bracket I worry I've typed it early on accident. If it tries to auto wrap my selection, I'm confused about what I typed. I don't care how advanced and fancy this feature gets, just leave me a way out. please.

@rebornix
Copy link
Member

rebornix commented Sep 5, 2018

I played with latest Code Insiders, and selecting a ' and typing " will not auto surround it.

BTW, we introduced editor.autoClosingQuotes and editor.autoClosingBrackets to help better control when they should be auto paired. Let us know your feedback on them. Thanks!

@rebornix rebornix closed this as completed Sep 5, 2018
@jkyeung
Copy link

jkyeung commented Sep 5, 2018

I am very glad that brackets and quotes can now be autoclosed separately. I've got autoclosing disabled for brackets and enabled for quotes. So far, so good. This seems to have the happy side-effect that the behavior of prefixed strings in Python (like b'foo' for bytes, r'foo' for raw, and u'foo' for Unicode) is fixed.

I actually would use autoclosing brackets too if not for their interaction with autoindent, as I described in #34861. That is a show-stopper for me.

I have an open question for everyone who uses autoclosing brackets:

Once you've created some code like the following (pretend that the pipe character is the cursor):

x = (
    |
)

After you're done typing the contents that go between the parens, how do you get past that closing paren? Do you use arrow keys? Do you use the mouse? I am genuinely curious about this, because I think it is the only thing stopping me from turning autoclose on for brackets.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 20, 2018
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-autoclosing Editor automatic closing of parens / brackets / etc.
Projects
None yet
Development

No branches or pull requests

8 participants