Skip to content

✨ Save and restore selection state in undo/redo#8652

Open
eureka928 wants to merge 3 commits intopenpot:developfrom
eureka928:feat/undo-redo-selection-state
Open

✨ Save and restore selection state in undo/redo#8652
eureka928 wants to merge 3 commits intopenpot:developfrom
eureka928:feat/undo-redo-selection-state

Conversation

@eureka928
Copy link
Contributor

Related Ticket

#6007

Summary

Selection state is now saved alongside each undo entry and restored when performing undo/redo operations. Previously, undoing an action did not restore the selection, forcing users to manually reselect elements.

How it works:

  • selected-before is captured in commit-changes (before changes are applied to state)
  • selected-after is captured in append-undo (after changes are applied)
  • On undo, the selection reverts to selected-before (what was selected before the action)
  • On redo, the selection restores to selected-after (what was selected after the action)

All three undo entry paths are handled:

  • add-undo-entry: new entries get both fields
  • stack-undo-entry: keeps original selected-before, updates selected-after
  • accumulate-undo-entry: keeps first selected-before, updates selected-after
  • Group undo/redo: uses first item's selected-before and last item's selected-after

Steps to reproduce

  1. Select a shape and move it
  2. Press Ctrl+Z to undo
  3. Verify the shape is still selected after undo
  4. Select multiple shapes, delete them
  5. Press Ctrl+Z to undo the delete
  6. Verify the deleted shapes are restored AND re-selected
  7. Press Ctrl+Shift+Z to redo
  8. Verify selection is cleared (as it was after the delete)

Checklist

  • Choose the correct target branch; use develop by default.
  • Provide a brief summary of the changes introduced.
  • Add a detailed explanation of how to reproduce the issue and/or verify the fix, if applicable.
  • Include screenshots or videos, if applicable.
  • Add or modify existing integration tests in case of bugs or new features, if applicable.
  • Refactor any modified SCSS files following the refactor guide.
  • Check CI passes successfully.
  • Update the CHANGES.md file, referencing the related GitHub issue, if applicable.

@niwinz niwinz self-assigned this Mar 17, 2026
Save current selection IDs in commit-changes so undo entries
can track what was selected before each action.

Signed-off-by: eureka928 <meobius123@gmail.com>
Extend undo entry with selected-before and selected-after fields.
On undo, restore selection to what it was before the action.
On redo, restore selection to what it was after the action.
Handles single entries, stacked entries, accumulated transactions,
and undo groups.

Fixes penpot#6007

Signed-off-by: eureka928 <meobius123@gmail.com>
Pass the captured selection state from commit data into
the undo entry so it is stored alongside changes.

Signed-off-by: eureka928 <meobius123@gmail.com>
@eureka928 eureka928 force-pushed the feat/undo-redo-selection-state branch from 2ec0872 to 4b84e94 Compare March 18, 2026 19:36
@niwinz
Copy link
Contributor

niwinz commented Mar 23, 2026

will look on it tomorrow

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