Skip to content

fix: onChange is called when the sketch changed (#80) - #204

Merged
tbolis merged 1 commit into
release/1.1.0from
fix/onchange-only-when-changed
Nov 2, 2026
Merged

tbolis merged 1 commit into
release/1.1.0from
fix/onchange-only-when-changed

Conversation

@tbolis

@tbolis tbolis commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Summary

onChange was called 10 ms after every mouse up and mouse out on the canvas, whether or not the drawing changed (issue #80). A click which only selects, a drag of the pan tool, and a pointer which comes and goes all called it.

  • The events manager notes that an object was added, modified or removed since the mouse was pressed, and tells the application only then.
  • A change is told once: a drawing which the mouse leaves the canvas in the middle of calls onChange at the mouse out, and the release outside of the canvas has nothing more to tell.
  • A change made before the press (an object added by code) does not make the next click one.
  • undo, redo and the load of a value call onChange as before. The eraser, the laser pointer and the polygon tell the application themselves, as before. A pinch gesture still calls nothing.
  • README: the onChange row, and the limitation of Add functions like onUpdate() or onChange() with old snapshots and newly added objects. #80 is removed. The limitation "Drawing an arrow records undo steps which have no visible effect" is removed too, as fix: an arrow is one undo step #201 fixed it. CHANGELOG: a line under Changed in 1.1.0. The type comment of onChange follows.

Changes of behavior

An application which used onChange as "the mouse was released" now gets it only when the sketch changed. The objects it needs are in onObjectAdded, onObjectModified and onObjectRemoved, which are not changed.

Checks

yarn format:check, yarn lint, yarn typecheck and yarn build pass. yarn test: 434 passing and 1 todo. The new tests, the onChange ones in SketchField.spec.tsx and onChange.spec.tsx (with the mouse events of the browser: a drawing, the move of an object with the select tool, a click which selects, a drag in the empty part, a pointer which leaves, a mouse out in the middle of a drawing, a free stroke, the pan tool), fail without the change: 7 of them.

Notes for review

onChange was called 10 ms after every mouse up and mouse out, whether or not
the drawing changed: a click which selects, a drag of the pan tool and a
pointer which comes and goes all called it. The events manager now notes that
an object was added, modified or removed since the mouse was pressed, and
tells the application only then, once: the release which follows a mouse out
in the middle of a drawing has nothing more to tell. undo, redo and the load
of a value call onChange as before.

The README no longer lists the limitation, nor the one of the arrow's undo
steps, which #201 fixed.
@tbolis
tbolis merged commit deb31ce into release/1.1.0 Nov 2, 2026
3 checks passed
@tbolis
tbolis deleted the fix/onchange-only-when-changed branch November 2, 2026 11:01
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.

1 participant