[selection] add commands to sort selected rows #2295
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proof-of-concept command that sorts only the rows in the selection. @daviewales requested such a feature and I wanted it too.
I recommend using the c79ce4f commit for testing. It uses a temporary workaround for #2266 to allow undo. Otherwise you can't undo the sort. And it uses assertions to detect if rows are lost.
If you think this is worth including, I would appreciate a close inspection of this, @saulpw and @anjakefala , as my first few versions of this caused data corruption.
The practical use of it is a bit limited. Right now you can use
sort-selected-asc
and-desc
to sort by the current column. But if you want to sort by multiple columns you'll have to do it by hand, viaexec-python
and thensortSelected(ordering)
.ordering
is a list of (column, boolean) tuples. The boolean is a direction;False
means ascending,True
means descending. For example,sortSelected([(row1, False), ('title2', True), ('title3'), False)])
.I can imagine a way to reorder rows more flexibly. The user could pull the selection into a new sheet with
"
, reorder the sheets using keys like[
andz[
, or even by sliding rows up and down. And then use a new command to replace the source row selection with the reordered rows. What do you think of that?