Skip to content

Commit

Permalink
Prevent widget from accidentally moving when clicked #671
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 19, 2024
1 parent 8e0775a commit bc8027a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
6 changes: 4 additions & 2 deletions packages/project-editor/features/changes/flow-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ export const Canvas = observer(
movementX: event.movementX ?? 0,
movementY: event.movementY ?? 0,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
timeStamp: event.timeStamp
};

this.mouseHandler.down(this.props.flowContext, event);
Expand All @@ -465,7 +466,8 @@ export const Canvas = observer(
? this.mouseHandler.lastPointerEvent.movementY
: 0,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
timeStamp: event.timeStamp
};

this.mouseHandler.move(this.props.flowContext, event);
Expand Down
6 changes: 4 additions & 2 deletions packages/project-editor/features/page/PageTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ const TimelineEditor = observer(
movementX: e.movementX ?? 0,
movementY: e.movementY ?? 0,
ctrlKey: e.ctrlKey,
shiftKey: e.shiftKey
shiftKey: e.shiftKey,
timeStamp: e.timeStamp
};

const dragSettings = hitTest(this.props.timelineState, e, x1, y1);
Expand Down Expand Up @@ -763,7 +764,8 @@ const TimelineEditor = observer(
movementX: e.movementX ?? 0,
movementY: e.movementY ?? 0,
ctrlKey: e.ctrlKey,
shiftKey: e.shiftKey
shiftKey: e.shiftKey,
timeStamp: e.timeStamp
};

const rectSvg = this.svgRef.current!.getBoundingClientRect();
Expand Down
6 changes: 4 additions & 2 deletions packages/project-editor/flow/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ export const Canvas = observer(
movementX: event.movementX ?? 0,
movementY: event.movementY ?? 0,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
timeStamp: event.timeStamp
};

this.mouseHandler.down(this.props.flowContext, event);
Expand All @@ -669,7 +670,8 @@ export const Canvas = observer(
? this.mouseHandler.lastPointerEvent.movementY
: 0,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
timeStamp: event.timeStamp
};

this.mouseHandler.move(this.props.flowContext, event);
Expand Down
13 changes: 7 additions & 6 deletions packages/project-editor/flow/editor/mouse-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface IPointerEvent {
movementY: number;
ctrlKey: boolean;
shiftKey: boolean;
timeStamp: number;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -91,7 +92,7 @@ export class MouseHandler implements IMouseHandler {
down(context: IFlowContext, event: IPointerEvent) {
this.transform = context.viewState.transform;

this.timeAtDown = new Date().getTime();
this.timeAtDown = event.timeStamp;

this.lastOffsetPoint = this.offsetPointAtDown =
this.transform.pointerEventToOffsetPoint(event);
Expand All @@ -106,7 +107,7 @@ export class MouseHandler implements IMouseHandler {
move(context: IFlowContext, event: IPointerEvent) {
this.transform = context.viewState.transform;

this.elapsedTime = new Date().getTime() - this.timeAtDown;
this.elapsedTime = event.timeStamp - this.timeAtDown;

let offsetPoint = this.transform.pointerEventToOffsetPoint(event);

Expand Down Expand Up @@ -395,13 +396,13 @@ export class DragMouseHandler extends MouseHandlerWithSnapLines {
move(context: IFlowContext, event: IPointerEvent) {
super.move(context, event);

if (this.elapsedTime < 100 && this.distance < 20) {
return;
}

this.left += this.movement.x / context.viewState.transform.scale;
this.top += this.movement.y / context.viewState.transform.scale;

if (this.elapsedTime < 200 && this.distance < 10) {
return;
}

const { left, top } = this.snapLines.dragSnap(
this.left,
this.top,
Expand Down
6 changes: 4 additions & 2 deletions packages/project-editor/flow/runtime-viewer/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ export const Canvas = observer(
movementX: event.movementX ?? 0,
movementY: event.movementY ?? 0,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
timeStamp: event.timeStamp
};

this.mouseHandler.down(this.props.flowContext, event);
Expand All @@ -345,7 +346,8 @@ export const Canvas = observer(
? this.mouseHandler.lastPointerEvent.movementY
: 0,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
timeStamp: event.timeStamp
};

this.mouseHandler.move(this.props.flowContext, event);
Expand Down

0 comments on commit bc8027a

Please sign in to comment.