Skip to content

feat(canvas): implement core element locking with eraser immunity - #38

Merged
shadowmkj merged 2 commits into
mainfrom
lock-elements
Nov 14, 2026
Merged

shadowmkj merged 2 commits into
mainfrom
lock-elements

Conversation

@shadowmkj

Copy link
Copy Markdown
Owner

Summary

This PR introduces core canvas element locking capabilities to protect elements from accidental modifications or deletions. It includes robust hit-testing exclusions for locked elements (making them immune to eraser and selection dragging unless specifically overridden), visual overlays with a lock badge and dashed selection bounds, keybinding support for toggling locks (Cmd/Ctrl + Shift + L), and history undo/redo compatibility.

Closes: #29

Key Changes

  • Element Locking State & Commands: Added locked property to canvas element types, implemented SetElementsLockCommand in the history stack, and registered the selection.toggle_lock command.
  • Hit-Tester & Pointer Router Adjustments:
    • Updated hitTestPoint and hitTestMarquee to ignore locked elements by default unless specified via options (e.g., holding Shift during marquee selection allows selecting locked elements).
    • Ensured the eraser tool completely ignores locked elements and allows erasing unlocked elements underneath.
    • Blocked movement/resizing on selected locked elements while still allowing them to be clicked and selected.
  • Visual Overlays & Settings:
    • Updated SelectionOverlay to hide resize handles, display a dashed stroke, and render a lock HUD badge when locked elements are selected.
    • Added keybinding configuration (<D-S-l>) and Visual Mode action definitions for toggling locks.
  • Document & History Preservation: Updated ClearCanvasCommand so that locked elements are preserved when clearing the canvas.

Verification & Testing

  • Automated Tests:
    • Added test cases in HitTester.test.ts verifying marquee and point hit-testing behaviors with ignoreLocked and includeLocked options.
    • Added test cases in PointerRouter.test.ts for eraser tool immunity, selecting locked elements without drag mobility, and Shift-marquee multi-selection.
    • Added tests in SelectionOverlay.test.tsx and CommandRegistry.test.ts for lock badges and command execution/history undo/redo.
  • Manual Verification: Run test suite via npm test or the workspace test runner to verify all canvas interaction and state unit tests pass successfully.

@shadowmkj
shadowmkj merged commit 1545467 into main Nov 14, 2026
2 checks passed
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.

feat(canvas): Element locking support to protect elements from accidental erasure, movement, and deletion

1 participant