Skip to content

LR-FILT-SORT: Previous Shuffle and a Reshuffle shortcut (stacked on #3288) - #3294

Open
nledford wants to merge 4 commits into
storytold:mainfrom
nledford:shuffle-previous
Open

nledford wants to merge 4 commits into
storytold:mainfrom
nledford:shuffle-previous

Conversation

@nledford

@nledford nledford commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3288.

Problem

Reshuffle replaces the random order for good: if the new shuffle is worse than the one before, there is no way back, and nothing in either Sort menu or on the keyboard offers a Reshuffle or a way to undo one. Undo is for edits only, so it can't help.

Change

  • A new command, library.previousShuffle ("Previous Shuffle"), goes back to the exact order the last Reshuffle replaced, by its seed, and again for the one before it, up to 32 steps. It is on only while the Reshuffle row is on (sorting at random, not in Recently Added) and an earlier shuffle exists.
  • The seeds a Reshuffle (or a new seed given while shuffling) replaces are kept in the session only: never saved with the view, never an undo step. They are forgotten when the sort leaves Random and when another library opens. Going back is not itself kept, so a Reshuffle after it makes a new order.
  • A Reshuffle after going back is a new order even within the same clock second: each new seed also mixes in a count of the shuffles made this session (before, a seed depended only on the previous seed and the clock's second, and nothing ever returned to an earlier seed).
  • Previous Shuffle sits right under Reshuffle in the bottom bar's Sort popup and in View ▸ Sort (hidden from the generic View listing, like Reshuffle). Both rows show their keys: Reshuffle ⌘⌥⇧R and Previous Shuffle ⌘⌥⇧P (Ctrl+Alt+Shift+R / P). Both are free in the default keymap (the keymap's uniqueness test covers them) and keep clear of the keys text fields take (Z, Y, V, C, X, A).
  • On Windows and Linux a key press goes straight to the command, so the two keys follow the menus' rule: they do nothing where the menu rows are off (a date sort, Recently Added). The macOS menu bar enforces the same through its disabled rows.
  • The engine API is unchanged for callers: library.shuffle and library.sort accept what they did; only their help text mentions the history.
  • One new string ("Previous Shuffle") in all 17 catalogs, worded with each catalog's own Reshuffle. docs/library-shortcuts.md, docs/whats-new.md, docs/parity-checklist.md (LR-FILT-SORT, MENU-VIEW-SORT, revision row).

Not in this PR: a visible chip or header for the current shuffle, the grid's scroll position after a reshuffle, and a Custom Order key (#1155).

How it was checked

  • cargo xtask ci passes on this branch (all 8 steps: fmt, clippy, heif, test, parity, layers, assets, wasm; 5,260 tests passed, 42 ignored; run on 755f858, the head's one later commit changes only a doc comment, and clippy passed on it), on main at 77c0a6a with MENU-VIEW-SORT: the Sort menus offer only what the view uses #3288 below it. It ran with the one-file clippy fix of MENU-BAR: clippy passes on macOS again (Quit, About and Settings share one branch) #2973 applied uncommitted, because main fails clippy at apps/lightcraft/src/native_menu.rs:492 on macOS ("this if has identical blocks"); the diff was reverted before the commit.
  • A test that fails without this change: on the engine, three tests in crates/engine/src/tests/libops.rs (the exact earlier order, a bounded history, off unless sorting at random) fail with assertion failures against a stub command. In the UI crate, previous_shuffle_follows_reshuffle_and_both_show_their_shortcuts (menu model) and the_popups_previous_shuffle_brings_back_the_order_a_reshuffle_replaced (the popup's rows) fail with that push removed; the_shuffle_keys_follow_the_sort_menus_rules (keymap) fails without the guard (Reshuffle switched a date sort to Random); opening_a_library_forgets_the_earlier_shuffles and the added assertion in previous_shuffle_restores_… (a Reshuffle after going back is not the order just left) fail before their fixes.
  • User-visible change: ran the app on this Mac (release build, procedural demo library, control channel) and looked at the popup under Random after a Reshuffle; screenshots below. View ▸ Sort is the native menu bar, which was not driven: its rows come from the same model (ui.menu.tree and the menu tests read it), including the keys.
  • Review: fresh reviewer at 755f858; later: wording only (cc6fe89)

Screenshots

The bottom bar's Sort popup, demo library, sorted at random after a Reshuffle. Before (#3288): Reshuffle without a key and nothing to go back with. After: Reshuffle shows ⌘⌥⇧R and Previous Shuffle ⌘⌥⇧P is on.

Before
After

Merging

Checklist

  • No new panic path in non-test code: no unwrap / expect / panic!, no indexing or unchecked arithmetic on a number from a file, a person or an agent (get, checked_mul, NaN and char boundaries handled)
  • New text on screen goes through tr() and has its key in crates/ui-egui/locales/*.json; a new shortcut is free in docs/library-shortcuts.md
  • The feature's rows in docs/parity-checklist.md and its entry in docs/gaps.md are updated, honestly (🟡 when it is partial), in the same commit (docs/gaps.md has no entry for the Sort menus)
  • New code has a caller: no command, module or setting that nothing reaches yet
  • Ready to merge (otherwise open it as a draft)

Summary by CodeRabbit

  • New Features
    • Added Previous Shuffle to restore up to 32 recently replaced random orders during the current session.
    • Added shortcuts for reshuffling and restoring the previous shuffle.
    • Sort menus now show which controls are available for the current view and sorting mode, with explanations when options are unavailable.
  • Documentation
    • Updated shortcut guides and release notes with the new actions and sorting behavior.

Recently Added is always newest import first: its keys, direction and Reshuffle are off, nothing is checked as the order shown, and a dim line says why. Under Random and in Recently Deleted the date groups are off and unchecked. Reshuffle is listed in both menus under its own separator below the keys. The bottom bar's popup and View > Sort read one model (menus/sort_menu.rs).
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The engine now tracks prior random shuffle orders for the current session. Both Sort menus use shared rules for control availability, including Reshuffle and Previous Shuffle, and display explanatory notes for Recently Added and Recently Deleted.

Changes: Shuffle history and restoration

Layer / File(s) Summary
Track and restore random orders
crates/engine/src/cmd/library/specs.rs, crates/engine/src/lib.rs, crates/engine/src/library.rs, crates/engine/src/tests/libops.rs
The session tracks replaced random seeds, retains up to 32, and clears history when leaving Random or opening another library. library.previousShuffle restores the latest seed when available. Tests cover restoration, history limits, and clearing conditions.

Sort menu availability and presentation

Layer / File(s) Summary
Model and render sort-menu availability
crates/ui-egui/src/menus.rs, crates/ui-egui/src/menus/sort_menu.rs, crates/ui-egui/src/menus/menubar.rs, crates/ui-egui/src/panels/bottombar.rs, crates/ui-egui/src/shortcuts.rs, crates/ui-egui/src/menus/menubar/tests.rs, crates/ui-egui/src/tests.rs, crates/ui-egui/src/tests/sort_menu.rs
A shared SortMenu model provides enabled and checked states and explanatory notes. Both Sort menus use it for sort keys, direction, date groups, Reshuffle, and Previous Shuffle. Tests cover menu states and interactions.

Shortcuts and user-facing guidance

Layer / File(s) Summary
Shortcuts, translations, and documentation
crates/ui-egui/src/tests/keymap.rs, crates/ui-egui/locales/*.json, docs/library-shortcuts.md, docs/parity-checklist.md, docs/whats-new.md
Shortcut tests cover Reshuffle and Previous Shuffle behavior. Locale files add sort notes and the Previous Shuffle label. Documentation describes command shortcuts, availability, and session history.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SortMenu
  participant fire_command
  participant LibraryCommand as library.previousShuffle
  participant Session
  User->>SortMenu: invoke Previous Shuffle
  SortMenu->>fire_command: dispatch enabled command
  fire_command->>LibraryCommand: execute command
  LibraryCommand->>Session: restore latest replaced seed
Loading

Suggested reviewers: claude, emmertex, skylartaylor

Merge Risk: Minimal · up to cc6fe

Shuffle history and sort controls are ready to merge after normal checks.

Security architecture risk: Minimal · up to cc6fe

The new functionality changes photo ordering within the current session without adding permissions or a new access channel. History is bounded and kept separate from saved history and edit undo. No material security regression was identified in the reviewed paths.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new capability affects ordering and restoration within the Session already controlled by the caller. Its handlers do not introduce cross-library asset selection, another service's authority, or a new sensitive destination; saved current-sort changes use the existing view persistence path.

Trust Boundaries and Controls

  • inferred — An existing MCP caller can invoke the newly registered command through the established engine boundary, but gains only session-local seed restoration. The difference between UI availability and direct-engine availability does not demonstrate a control bypass because the view restriction is not caller authorization.

Resilience and Maintainability Implications

  • observed — History storage is bounded to 32 seeds. Invalid seeds are rejected before history mutation, unavailable restoration is rejected before popping, and command execution requires exclusive mutable Session access.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main changes: Previous Shuffle and a Reshuffle shortcut. It is concise and directly matches the pull request objectives.
Docstring Coverage Passed Docstring coverage is 90.48% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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: Docstring Coverage

Explanation

Docstring coverage is 90.48% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 21 functions across 13 files. (20 skipped: 20 unsupported.)

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.0)

Clippy execution timed out

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🔇 Additional comments: 1
crates/engine/src/cmd/library/specs.rs-55-58: 1

55-58: Minor · Functional Correctness · Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Disable Previous Shuffle in Recently Added at the engine boundary.

If a user reshuffles under Random and then opens Recently Added, can_go_back still enables library.previousShuffle for direct engine clients. The command pops a history entry without changing the order shown in Recently Added. When the user returns to another source, that entry is no longer available. Reject Recently Added in can_go_back, as the Sort menus already do. (raw.githubusercontent.com)


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 77c0a6a and cc6fe89.

Files selected for processing: 33
  • crates/engine/src/cmd/library/specs.rs
  • crates/engine/src/lib.rs
  • crates/engine/src/library.rs
  • crates/engine/src/tests/libops.rs
  • crates/ui-egui/locales/cs.json
  • crates/ui-egui/locales/de.json
  • crates/ui-egui/locales/es.json
  • crates/ui-egui/locales/fi.json
  • crates/ui-egui/locales/fr.json
  • crates/ui-egui/locales/id.json
  • crates/ui-egui/locales/it.json
  • crates/ui-egui/locales/ja.json
  • crates/ui-egui/locales/ka.json
  • crates/ui-egui/locales/pl.json
  • crates/ui-egui/locales/pt-br.json
  • crates/ui-egui/locales/ru.json
  • crates/ui-egui/locales/sv.json
  • crates/ui-egui/locales/uk.json
  • crates/ui-egui/locales/vi.json
  • crates/ui-egui/locales/zh-hans.json
  • crates/ui-egui/locales/zh-hant.json
  • crates/ui-egui/src/menus.rs
  • crates/ui-egui/src/menus/menubar.rs
  • crates/ui-egui/src/menus/menubar/tests.rs
  • crates/ui-egui/src/menus/sort_menu.rs
  • crates/ui-egui/src/panels/bottombar.rs
  • crates/ui-egui/src/shortcuts.rs
  • crates/ui-egui/src/tests.rs
  • crates/ui-egui/src/tests/keymap.rs
  • crates/ui-egui/src/tests/sort_menu.rs
  • docs/library-shortcuts.md
  • docs/parity-checklist.md
  • docs/whats-new.md

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

@vangel76 vangel76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed cc6fe89e. I traced the Previous Shuffle action, stored history, and the sort direction. I found one case where it restores a different order. The submitted branch currently conflicts with main.

Source review only. I did not build the project, run tests, or check CI.

can_go_back,
|s, _| {
let seed = s.shuffle_history.pop().ok_or_else(|| bad("library.previousShuffle", "no earlier shuffle"))?;
s.sort = Sort { seed, ..s.sort };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2. Restore the sort direction with the previous shuffle seed. Random order also honors ascending, but this history saves only the seed. Shuffle while ascending, reshuffle, change direction, then use Previous Shuffle: it restores the old seed under the new direction. Store both values or clear the history on a direction change. Cover that sequence in the shuffle regression.

@wanikhawar wanikhawar 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.

This edits translation files in crates/ui-egui/locales. Translations go to storytold/craft-i18n, and feature PRs add English only (rule 16). Please move the locale edits there and keep English only here. It is stacked on #3288, which needs the same change, and it conflicts with main.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants