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

apply topological sort to reorder cells in editor #3560

Open
tmchartrand opened this issue Jan 24, 2025 · 5 comments
Open

apply topological sort to reorder cells in editor #3560

tmchartrand opened this issue Jan 24, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@tmchartrand
Copy link

tmchartrand commented Jan 24, 2025

Description

In many cases, I add a cell out of its topological order simply for convenience when editing (ie working with a later portion of the notebook and realize a needed variable was not defined). In this case the work would be more polished for a reader if the cells were reordered to match the topological order (as is currently done when exporting).

Suggested solution

Add a UI command that reorders cells in their topological order.
Also consider a cell-level command that moves that cell only to immediately above the first dependent cell.

Alternative

This can currently be done manually.

Additional context

No response

@tmchartrand tmchartrand added the enhancement New feature or request label Jan 24, 2025
@akshayka
Copy link
Contributor

Sounds like a reasonable request. How would you handle things like mo.md(), which might float to the top or coalesce together?

@tmchartrand
Copy link
Author

I guess I haven't looked in detail at how the current topological sort does it, but I would suggest looking for the minimal reordering compatible with the topological constraints (in some loose sense anyway, not sure if this is well-defined) , so cells not on the dependency tree just wouldn't move.

@tmchartrand
Copy link
Author

Ah, I see ties are currently broken by registration order - seems reasonable, but for this application it would be preferable to use the current layout order for that I think.

@mscolnick
Copy link
Contributor

I could be thinking about layout order wrong, but in my interpretation, that would for sure bubble up markdown to the top. Maybe there is some algorithm/ruleset that would be agreeable (like sorting between pure-markdown blocks, but i can still think of edge cases).

@tmchartrand
Copy link
Author

Oh yes of course, they'll always be clumped if the use of existing order is just to break ties.
I guess it makes more sense in my initial framing, a minimal reordering compatible with the topological constraints (maybe just a simple insertion sort following the dependency tree). Then the markdown cells would remain in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants