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

[feature request] Sort lines by selection #129

Open
amok opened this issue Sep 19, 2023 · 4 comments
Open

[feature request] Sort lines by selection #129

amok opened this issue Sep 19, 2023 · 4 comments

Comments

@amok
Copy link

amok commented Sep 19, 2023

Use case: sort lines by keys

Example

  1. input:
type Data = {
  buyers?: string[];
  recordingDate: SomeRecordingDate;
  saleDate: SaleDateType;
  documentNumber: string;
  documentType: string;
  resale?: boolean;
};
  1. Select keys

image

  1. Execute "sort lines" extension command

  2. output:

type Data = {
  buyers?: string[];
  resale?: boolean;
  saleDate: SaleDateType;
  documentType: string;
  recordingDate: SomeRecordingDate;
  documentNumber: string;
};

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 imports etc.

@Tyriar
Copy link
Owner

Tyriar commented Sep 25, 2023

You want to sort lines by the length of the key?

@amok
Copy link
Author

amok commented Sep 26, 2023

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:
image

output:
image


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"

screencast.2023-09-26.10-46-27.mp4

@ranolfi
Copy link

ranolfi commented May 14, 2024

@amok, does the following extension do exactly what you want? Sort Lines by Selection by earshinov.

@amok
Copy link
Author

amok commented May 14, 2024

@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']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants