-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
[selection] add commands to sort selected rows #2295
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these commands should go in their own file, either features/sort_selected.py
or experimental/sort_selected.py
. I'm leaning towards the latter, because while the code looks right to me, the idea in general makes me nervous--what if the user aborts this thread with Ctrl+C
after the sort but before the replacement? It feels like these should be opt-in, use-at-your-own-risk commands, for the time being at least.
I made the other changes to the sort API to support this, and because they feel better in general.
Good points about cancelling being dangerous! I hadn't considered that. We could bypass this if we could edit a copy of the rows and then assign it to Line 72 in aab3cda
|
Use assertions to ensure no sheet data is lost.
With
It's an edge case for sure, but one that I ran across and felt important to make work for internal design consistency. |
Oh, I see. Assigning to I'll search the git logs more in the future, that note is still helping, 5 years 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?