Open amok opened 9 months ago
You want to sort lines by the length of the key?
You want to sort lines by the length of the key?
Not really. I'd like to sort by the length of what I selected Here is another example
input:
output:
PS The problems with "sort by keys" is with this "what is the key?" built in logic F.e, I have Sort JSON extension installed but almost never use it :) since it works only on valid JSON (quoted keys and no extra commas and etc) - using that extension I cannot easily "sort by keys" named Python (see below) dict or TypeScript (example in the description) type definition, or.. what about PHP associative array?
thisdict = { # <----- oops, this is "invalid JSON" line
"brand": "Ford",
"year": 1964
}
array( // And this does not look like JSON at all
"Peter"=>"35",
"Ben"=>37
);
Whether it would be really convenient to use cmd+d
(maybe in combination with cmd+k cmd+d
) or cmd+shift+L
to "select all occurrences" and then option+shift+left
to "select to the left" and the "sort lines by selection"
https://github.com/Tyriar/vscode-sort-lines/assets/1369559/f8984d05-2edc-4da9-a6ce-95857aec1494
@amok, does the following extension do exactly what you want? Sort Lines by Selection by earshinov.
@amok, does the following extension do exactly what you want? Sort Lines by Selection by earshinov.
Unfortunately, nope. It applies natural sort to the selection. The issue primarily is about sorting by length, something like:
const selected = ['aaa', 'aa', 'xx', 'fffff']
const sorted = selected.toSorted((a, b) => a.length - b.length)
// --> ['aa', 'xx', 'aaa', 'fffff']
Use case: sort lines by keys
Example
1) input:
2) Select keys
3) Execute "sort lines" extension command
4) output:
This would be similar to "JSON: sort by keys", but this functionality is also useful for TS', Python' and other kind of objects, dicts, and also
import
s etc.