Skip to content

Commit

Permalink
prevent offset out of bounds
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
lakhoune committed Mar 14, 2023
1 parent 99d4fa4 commit 7187832
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion widgets/src/es6/canvas_widget/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2677,14 +2677,23 @@ export class AbstractNode extends AbstractEntity {
if (params.el.id !== this._$node.attr("id")) return true;
setTimeout(() => {
_$node.css({ opacity: "" });
// _$node.resizable("enable");
_canvas.bindMoveToolEvents();
var offsetX = Math.round(
(_$node.position().left - originalPos.left) / _canvas.getZoom()
);
var offsetY = Math.round(
(_$node.position().top - originalPos.top) / _canvas.getZoom()
);
// if offset is 0, no need to send the operation
if (offsetX === 0 && offsetY === 0) return;
// if offset bigger than canvas size, no need to send the operation
if (
Math.abs(offsetX) > _canvas.width ||
Math.abs(offsetY) > _canvas.height
) {
console.error(" offset bigger than canvas size");
return;
}

var operation = new NodeMoveOperation(
that.getEntityId(),
Expand Down Expand Up @@ -2885,6 +2894,7 @@ export class AbstractNode extends AbstractEntity {
square: true,
listeners: {
move(event) {
jsPlumbInstance.setDraggable(that._$node.get(0), false);
let { x, y } = event.target.dataset;

x = (parseFloat(x) || 0) + event.deltaRect.left;
Expand Down

0 comments on commit 7187832

Please sign in to comment.