Undo/redo for encounter actions #16

Closed
opened 2026-03-25 15:58:49 +01:00 by dostulata · 0 comments
Owner

Summary

Add undo/redo capability for all encounter state changes using a snapshot (memento) approach. Before each state transition, the current Encounter is pushed to an undo stack (capped at 50 entries). The stacks are persisted to localStorage so undo/redo history survives page refresh. Triggered via UI buttons and keyboard shortcuts (Ctrl+Z / Ctrl+Shift+Z, Cmd on Mac).

Acceptance Criteria

  • Each encounter action pushes the pre-action state onto an undo stack (max 50 entries, oldest dropped)
  • Undo restores the previous encounter state and pushes the current state onto the redo stack
  • Redo restores the next encounter state and pushes the current state onto the undo stack
  • Any new action clears the redo stack
  • Undo/redo stacks are persisted to localStorage and restored on page load
  • Undo/Redo buttons are visible in the UI, disabled when their stack is empty
  • Ctrl+Z (Cmd+Z on Mac) triggers undo; Ctrl+Shift+Z (Cmd+Shift+Z) triggers redo
  • Keyboard shortcuts are suppressed while an input or textarea has focus, so browser-native undo is not intercepted
  • Clear encounter resets the undo/redo stacks

Dependencies

  • #15 (Atomic addCombatant) — required so each user action maps to exactly one undo entry

Context

  • Research: docs/agents/research/2026-03-25-combat-state.md (see "Follow-up Analysis" section)
## Summary Add undo/redo capability for all encounter state changes using a snapshot (memento) approach. Before each state transition, the current `Encounter` is pushed to an undo stack (capped at 50 entries). The stacks are persisted to localStorage so undo/redo history survives page refresh. Triggered via UI buttons and keyboard shortcuts (Ctrl+Z / Ctrl+Shift+Z, Cmd on Mac). ## Acceptance Criteria - [x] Each encounter action pushes the pre-action state onto an undo stack (max 50 entries, oldest dropped) - [x] Undo restores the previous encounter state and pushes the current state onto the redo stack - [x] Redo restores the next encounter state and pushes the current state onto the undo stack - [x] Any new action clears the redo stack - [x] Undo/redo stacks are persisted to localStorage and restored on page load - [x] Undo/Redo buttons are visible in the UI, disabled when their stack is empty - [x] Ctrl+Z (Cmd+Z on Mac) triggers undo; Ctrl+Shift+Z (Cmd+Shift+Z) triggers redo - [x] Keyboard shortcuts are suppressed while an input or textarea has focus, so browser-native undo is not intercepted - [x] Clear encounter resets the undo/redo stacks ## Dependencies - #15 (Atomic addCombatant) — required so each user action maps to exactly one undo entry ## Context - Research: `docs/agents/research/2026-03-25-combat-state.md` (see "Follow-up Analysis" section)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dostulata/initiative#16