From 7e109948fd202c2256f240a05a33afe2a1fde671 Mon Sep 17 00:00:00 2001 From: Aarush Karak Date: Fri, 4 Sep 2026 14:28:51 -0400 Subject: [PATCH] fix(edit-pdf): cover style changes with undo history Route patchSelected through commit so color/width/font/bold/italic edits land in the undo stack. updateAnno stays raw since it also serves drag/resize onChange. Fixes #21 --- src/operations/edit-pdf/index.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/operations/edit-pdf/index.jsx b/src/operations/edit-pdf/index.jsx index 36ea9f9..0281d42 100644 --- a/src/operations/edit-pdf/index.jsx +++ b/src/operations/edit-pdf/index.jsx @@ -287,7 +287,14 @@ export default function EditPdf() { const updateAnno = (id, patch) => setAnnos((prev) => prev.map((a) => (a.id === id ? { ...a, ...patch } : a))) // Apply a style change to the currently-selected annotation (if any). - const patchSelected = (patch) => selectedId && updateAnno(selectedId, patch) + // Goes through `commit` (not `updateAnno`) so style edits land in undo + // history. `updateAnno` stays raw on purpose: it also serves drag/resize + // `onChange`, which fires many updates per gesture. + const patchSelected = (patch) => { + if (!selectedId) return + const id = selectedId + commit((prev) => prev.map((a) => (a.id === id ? { ...a, ...patch } : a))) + } // ── erase (delete added items under the cursor) ── const distToSeg = (px, py, x1, y1, x2, y2) => {