Skip to content

Keep the current slide when moving a section - #2304

Open
MMexicann wants to merge 1 commit into
storytold:mainfrom
MMexicann:patch-35
Open

MMexicann wants to merge 1 commit into
storytold:mainfrom
MMexicann:patch-35

Conversation

@MMexicann

@MMexicann MMexicann commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Moving a section reorders the slides. The editor used to keep the old numeric slide index, which could make it jump to a different slide. Keep the active slide by ID and resolve its new index inside the same edit.

The regression checks the selected slide and slide order after moving a section, undoing it, and redoing it. The isolated Rust probe reproduced the wrong index and passed with the fix. It also checked that an empty section move leaves the fallback selection intact. rustfmt passed. The full engine suite was not run locally.

Summary by CodeRabbit

  • Bug Fixes
    • Moving a section now keeps the same slide selected, including after undoing or redoing the move.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

section_move now preserves the active slide selection when it reorders slides. A test checks the selection after the move and through undo and redo.

Changes: Section move selection

Layer / File(s) Summary
Restore selection after section move
crates/engine/src/cmd/slide.rs
section_move records the active slide ID before reordering and updates the selection index afterward. A test checks selection across the move, undo, and redo.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: echelon, dylanmtaylor, silvertree2010

Merge Risk: Minimal · up to 61631

Moving a section now keeps the same slide selected instead of switching to whichever slide lands at the old index. The change is small and local, it has a regression test, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Keep the current slide when moving a section" matches the changeset. The change in crates/engine/src/cmd/slide.rs records the active slide ID before section_move sorts slides and restores t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Keep the current slide when moving a section" matches the changeset. The change in crates/engine/src/cmd/slide.rs records the active slide ID before section_move sorts slides and restores the selection index from that ID afterward. A test checks that the current slide stays selected after a section move, undo, and redo. The title names the main behavior change and stays specific, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.1)

Clippy execution timed out
Clippy (1.99.1) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0ccc68f and 6163141.

Files selected for processing: 1

  • crates/engine/src/cmd/slide.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@autocraft-bot autocraft-bot Bot added the bugfix Fixes something that is broken: wrong result, crash, data loss label Nov 21, 2026

@autocraft-bot autocraft-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Claude Opus 5.5). Not a maintainer decision.

No blocking problems found (not certain).

section.move now captures the active slide's ID before reordering and restores its new index after the slides are re-sorted, so the selection stays on the same slide.

  • crates/engine/src/cmd/slide.rs:706 reads the active slide with doc.slides.get(sel.slide), so an out-of-range or empty selection is handled without panicking.
  • crates/engine/src/cmd/slide.rs:713-715 only updates sel.slide when the slide is still found, leaving the previous selection unchanged otherwise.
  • The new test moving_a_section_keeps_the_current_slide_selected covers the moved order and the selected slide after move, undo and redo.
  • Worth checking whether other commands that reorder slides keep an index-based selection in the same way and need the same ID-based remapping.

Claims checked:

  • verified: Moving a section keeps the active slide by ID and resolves its new index inside the same edit. (crates/engine/src/cmd/slide.rs:706 captures doc.slides.get(sel.slide).map(|slide| slide.id) before sections are moved; crates/engine/src/cmd/slide.rs:713-715 sets sel.slide from doc.slide_index(id) after…
  • unverified: The selected slide is kept after undoing and redoing a section move. (crates/engine/src/cmd/slide.rs:886-891 asserts the selection after edit.undo and edit.redo; whether Session::edit snapshots and restores the selection is decided outside the diff and could not be read.)
  • verified: An empty section move leaves the fallback selection intact. (crates/engine/src/cmd/slide.rs:713 only assigns sel.slide when both the active ID and its new index exist, so with no active slide the selection is left unchanged; no test in the diff covers this case.)

Reviewed at 6163141.

Recommendation: merge, after a maintainer's decision.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant