Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoring scrolling input when dragging on a plane #4085

Merged
merged 7 commits into from
May 13, 2019
Merged
11 changes: 11 additions & 0 deletions frontend/javascripts/libs/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class InputMouseButton {
}
}

let isDragging = false;

export class InputMouse {
targetId: string;
hammerManager: Hammer;
Expand All @@ -308,6 +310,7 @@ export class InputMouse {
position: ?Point2 = null;
triggeredByTouch: boolean = false;
delegatedEvents: { string?: Function };
ignoreScrollingWhileDragging: boolean;

// Copied from backbone events (TODO: handle this better)
on: (bindings: BindingMap<MouseHandler>) => void;
Expand All @@ -318,6 +321,7 @@ export class InputMouse {
targetId: string,
initialBindings: BindingMap<MouseHandler> = {},
id: ?string = null,
ignoreScrollingWhileDragging: boolean = false,
) {
_.extend(this, BackboneEvents);
this.targetId = targetId;
Expand All @@ -332,6 +336,8 @@ export class InputMouse {
this.rightMouseButton = new InputMouseButton("right", 3, this, this.id);
this.lastPosition = null;
this.delegatedEvents = {};
isDragging = false;
this.ignoreScrollingWhileDragging = ignoreScrollingWhileDragging;

document.addEventListener("mousemove", this.mouseMove);
document.addEventListener("mouseup", this.mouseUp);
Expand Down Expand Up @@ -403,13 +409,15 @@ export class InputMouse {

mouseDown = (event: MouseEvent): void => {
event.preventDefault();
isDragging = true;
this.lastPosition = this.getRelativeMousePosition(event);

this.leftMouseButton.handleMouseDown(event);
this.rightMouseButton.handleMouseDown(event);
};

mouseUp = (event: MouseEvent): void => {
isDragging = false;
this.leftMouseButton.handleMouseUp(event, this.triggeredByTouch);
this.rightMouseButton.handleMouseUp(event, this.triggeredByTouch);

Expand Down Expand Up @@ -507,6 +515,9 @@ export class InputMouse {

mouseWheel = (event: WheelEvent): void => {
event.preventDefault();
if (isDragging && this.ignoreScrollingWhileDragging) {
return;
}
let delta = 0;
if (event.deltaY != null) {
delta = -Number(event.deltaY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class PlaneController extends React.PureComponent<Props> {
inputcatcherId,
this.getPlaneMouseControls(id),
id,
true,
);
});
});
Expand Down