From 1fbb9f29ffbad905be70bd76ba453419008b07e9 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Wed, 1 Nov 2023 14:17:00 -0400 Subject: [PATCH] Fix dragging multiple anchors of a polyline object --- CHANGELOG.md | 5 +++++ client/Anchor.coffee | 3 +++ client/tools/modes.coffee | 8 +++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index deb4b4a..a392986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ To see every change with descriptions aimed at developers, see As a continuously updated web app, Cocreate uses dates instead of version numbers. +## 2023-11-01 + +* Fix dragging multiple anchors of a polyline object + [[#226](https://github.com/edemaine/cocreate/issues/226)] + ## 2023-08-09 * New polygonal line tool! diff --git a/client/Anchor.coffee b/client/Anchor.coffee index 58ba8b9..0a64e01 100644 --- a/client/Anchor.coffee +++ b/client/Anchor.coffee @@ -33,6 +33,9 @@ export anchorsOf = (obj) -> y: y + ty pointMove = (obj, moved, index, coords) -> + old = moved[index] ? obj.pts[index] + if old? + console.log old.x, old.y, 'vs', coords.x, coords.y if (old = moved[index] ? obj.pts[index])? and old.x == coords.x and old.y == coords.y false diff --git a/client/tools/modes.coffee b/client/tools/modes.coffee index fa0411b..2027da9 100644 --- a/client/tools/modes.coffee +++ b/client/tools/modes.coffee @@ -349,9 +349,11 @@ defineTool h.moved[id] ?= {} moved = false for index in anchorSelection.indicesForId id - x = obj.anchors[index].x + motion.x - y = obj.anchors[index].y + motion.y - moved or= anchorMove obj, h.moved[id], index, {x, y} + # Can't write `moved or=` because we don't want to short-circuit + if anchorMove obj, h.moved[id], index, + x: obj.anchors[index].x + motion.x + y: obj.anchors[index].y + motion.y + then moved = true continue unless moved diffs[id] = {id, pts: h.moved[id]} h.edit diffs if (id for id of diffs).length