-
-
Notifications
You must be signed in to change notification settings - Fork 18
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 object selection #79
Comments
[Hi. Thanks for the update kind words in your review] The code currently works by trying to convert the specifically selected text to JSON, so if what is selected isn’t JSON, then it can’t proceed. It could be possible to attempt to add missing brackets (and remove them before the final replacement), but this feels error prone. If you have specific ideas of how this might work, let me know. |
@richie5um I think most people would initially attempt what I did, aside from those wanting to sort an entire JSON file. That means supporting these two approaches for sorting an object/array inside a larger JSON file should be enough:
Currently, it seems only selecting exactly the object (starting and ending with the brackets) is supported. This could be solved by following these steps when parsing the selected code in order to find a valid JSON object:
|
@marcospgp I was about to uninstall the extension when I thought about checking the reviews first. Indeed, it's neither intuitive, nor well explained. Also, the original indentation is not kept, but I can live with that because I have an automatic formatter on save. |
3.5. If the extension looked pre and post the user's selection for the first matching pair of brackets (array), if not found, then braces (object), then worked from that range as the selection, but only processed the line numbers which the user's selection originally spanned across, maybe that would result in the desired effect? Problems: Obviously, the first matching pair of brackets / braces may be very far apart, or be on the same line as everything else if the JSON isn't formatted at all. If a pair doesn't exist, then fail like usual. |
@redactedscribe You mean detecting the object in question but only sorting the lines the user selected... Hm I don't think I see a use case for partial sorting of JSON objects/arrays. Most likely the user would be trying to simply point out which inner object they wanted to sort, and the partial sorting would be unintended (and could be hard to notice if there's for example only one non-selected line). |
I was using this extension for the first time and had some trouble figuring out how I could sort an object inside a larger JSON file.
Turns out I had to select exactly from the opening bracket
{
to the closing one}
.Intuitively, I expected selecting the lines (either the ones inside the brackets or also including the ones containing the brackets) to be enough, but when I attempted that, nothing happened. I initially thought the extension was simply broken.
Is there any chance sorting an object by selecting its interior lines or all lines including those with the brackets?
The text was updated successfully, but these errors were encountered: