Skip to content

Commit

Permalink
Fix anchor dragging bugs (#214)
Browse files Browse the repository at this point in the history
* Dragging non-defining corners of rectangles and ellipses was broken
* Moving to old location was accidentally forbidden
  • Loading branch information
edemaine committed Nov 21, 2022
1 parent f4389c0 commit 71365b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ To see every change with descriptions aimed at developers, see
As a continuously updated web app, Cocreate uses dates
instead of version numbers.

## 2022-11-21

* Fix anchor drag bugs: dragging non-defining corners of rectangles and
ellipses was broken, and moving to old location was accidentally forbidden
[[#214](https://github.com/edemaine/cocreate/issues/214)]

## 2022-11-17

* Arrowheads now work with pen tool
Expand Down
15 changes: 7 additions & 8 deletions client/Anchor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export anchorsOf = (obj) ->
y: y + ty

pointMove = (obj, moved, index, coords) ->
if (old = moved[index])? and old.x == coords.x and old.y == coords.y
false
else if (old = obj.pts[index])? and old.x == coords.x and old.y == coords.y
if (old = moved[index] ? obj.pts[index])? and
old.x == coords.x and old.y == coords.y
false
else
moved[index] =
Expand All @@ -44,11 +43,11 @@ pointMove = (obj, moved, index, coords) ->
export anchorMove = (obj, moved, index, coords) ->
if index > 1 and obj.type in ['rect', 'ellipse']
if index == 2
pointMove(obj, moved, 0, {x: coords.x, y: moved[0].y}) or
pointMove(obj, moved, 1, {y: coords.y, x: moved[1].x})
pointMove(obj, moved, 0, {x: coords.x, y: (moved[0] ? obj.pts[0]).y}) or
pointMove(obj, moved, 1, {y: coords.y, x: (moved[1] ? obj.pts[1]).x})
else if index == 3
pointMove(obj, moved, 1, {x: coords.x, y: moved[1].y}) or
pointMove(obj, moved, 0, {y: coords.y, x: moved[0].x})
pointMove(obj, moved, 1, {x: coords.x, y: (moved[1] ? obj.pts[1]).y}) or
pointMove(obj, moved, 0, {y: coords.y, x: (moved[0] ? obj.pts[0]).x})
else
console.error "Invalid anchor index #{index}"
else if 0 <= index < obj.pts.length
Expand Down Expand Up @@ -137,7 +136,7 @@ export class AnchorSelection
ops:
for obj in objs
before = pts: obj.pts
after = pts: obj.pts[..]
after = pts: {}
anchors = rawAnchorsOf obj
for index in @indicesForId obj._id
anchorMove obj, after.pts, index,
Expand Down

0 comments on commit 71365b9

Please sign in to comment.