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

CMD+D in JSON #10080

Closed
normalser opened this issue Aug 3, 2016 · 13 comments
Closed

CMD+D in JSON #10080

normalser opened this issue Aug 3, 2016 · 13 comments
Assignees
Labels
important Issue identified as high-priority json JSON support issues

Comments

@normalser
Copy link

  • VSCode Version: 1.4.0-insiders
  • OS Version: OSX

Steps to Reproduce:

  1. Create test.json file with content
{
    "key": [
        "This is test"
    ]
}
  1. Put your cursor inside test word
  2. Press CMD+D
  3. Problem: Entire string is selected - not a single word test

image

It works fine in .js file:
image

@aeschli
Copy link
Contributor

aeschli commented Aug 3, 2016

Each language can define what a 'word' is. For JSON it is the full string literal, which needs to be like that for other areas like code completion.

I'm not sure what's the design of Ctrl+D is. @alexandrudima Should it be the equivalent of doubleclick and use the configured wordSeparators?

@alexdima
Copy link
Member

@aeschli

Whaaat?

"This is a test" is a word in JSON ?

@alexdima alexdima assigned aeschli and unassigned alexdima Aug 12, 2016
@alexdima
Copy link
Member

I think the bug got introduced by this commit: 17e0d1c

@normalser
Copy link
Author

Just for comparison - both Atom and Sublime selects single word (eg. test) and not entire string in json files

@aeschli
Copy link
Contributor

aeschli commented Aug 12, 2016

@alexandrudima Not a bug, done intentionally. Other languages add @, !, : #, - _ to the word, which shows that what we call the 'word' regex is actually rather a 'token' regex.
One of the important use cases of the 'word' rule is in code completion to decide what is completed (how many characters are replaced). Also it decides what the 'word' based proposals of that language are. If you look at code completion JSON document without schema, you can see that the current proposals make much mores sense.

Why does Ctrl+D not use the wordSeparators as defined in editor.wordSeparator? It would be consistent to what double-click selects.

@aeschli
Copy link
Contributor

aeschli commented Sep 7, 2016

Closing as works as designed. Alex feel free to reopen if you think Ctrl +D should use use the wordSeparators.

@aeschli aeschli closed this as completed Sep 7, 2016
@normalser
Copy link
Author

@alexandrudima Please reconsider fixing it, arguments for it:

  1. Atom works that way
  2. Sublime works that way
  3. TextMate works that way
  4. .js works that way
  5. JSON is just subset of JS so seems natural that it should behave that way
  6. Personal - I need to work with a lot of "translation" files that happen to be .json files and being used to select word in json objects that reside in .js with CMD/Ctrl+D - I do the same in json object in .json files and it selects entire sentence which I overwrite and need Undo and then double click the word that I want to fix.
    (or at least ability to configure it in vscode would be awesome)

Thanks for reconsidering

@alexdima
Copy link
Member

alexdima commented Sep 8, 2016

@aeschli Here I am using VSCode version 0.10.8. Please notice how ctrl+d works correctly in JSON.

word-json

The bug was introduced when JSON changed its word definition regex in such a way that it now incorrectly identifier strings in quotes such as "Hello world, I am having a great day today" as a single word. IMHO there is no reasonable interpretation of the definition of a word that would agree with this broken regular expression.

Here is JSON's definition of a word definition in 0.10.8: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g

Here is JSON's definition of a word definition today: /("(?:[^\\\"]*(?:\\.)?)*"?)|[^\s{}\[\],:]+/

I will not change the behaviour of Ctrl-D because one language contains an incorrect word definition regular expression. I can, however hard code a good word definition in the editor core for json.

@alexdima alexdima reopened this Sep 8, 2016
@alexdima
Copy link
Member

alexdima commented Sep 8, 2016

I am adding the label important because this is a regression. @aeschli If you wish I can try finding the exact commit which introduced this regression.

@alexdima alexdima added the important Issue identified as high-priority label Sep 8, 2016
@aeschli
Copy link
Contributor

aeschli commented Sep 8, 2016

@alexandrudima The change was made intentionally, please read my comment above. It fixed various issues with code assist which I feel are equally important as Ctrl+D.
If nothing else it shows that the word-regex is overloaded, used in different contexts with different requirements. It describes 'words' in a language (I'd rather call them tokens), but also seems to be used for content inside comments and string literals. Maybe we need to split these up, or get code assist off the word regex.
I suggest we discuss it offline.

@mjbvz mjbvz added the json JSON support issues label Nov 12, 2016
@aeschli
Copy link
Contributor

aeschli commented Apr 7, 2017

We're in a deadlock here, IMO I don't see to get both camps here happy. Closing this been very few complaints on the CTRL+D behaviour in JSON I close this.

@aeschli aeschli closed this as completed Apr 7, 2017
@Vestride
Copy link

As it seems the default functionality won't change, is it possible to override the current behavior in my settings to be the same as JavaScript?

@cdeutsch
Copy link

cdeutsch commented Sep 7, 2017

Can you add that regex as a configurable setting?

Any other work arounds for those of us that value proper cmd+D behavior over code completion? Is there a way to map .json files as .js files?

As is, editing JSON files is very annoying when you're used to using cmd+D.

UPDATE:
You can remap .json to .js by adding this to your settings.json

{
    "files.associations": {
        "*.json": "javascript"
    }
}

@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
important Issue identified as high-priority json JSON support issues
Projects
None yet
Development

No branches or pull requests

6 participants