UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

87 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DragAwareMouseListener = void 0; /******************************************************************************** * Copyright (c) 2019-2024 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ const sprotty_1 = require("@eclipse-glsp/sprotty"); /** * A mouse listener that is aware of prior mouse dragging. * * Therefore, this listener distinguishes between mouse up events after dragging and * mouse up events without prior dragging. Subclasses may override the methods * `draggingMouseUp` and/or `nonDraggingMouseUp` to react to only these specific kinds * of mouse up events. */ class DragAwareMouseListener extends sprotty_1.MouseListener { constructor(dragSensitivity = 0) { super(); this._isMouseDown = false; this._isMouseDrag = false; this._dragSensitivity = 0; this._dragSensitivity = dragSensitivity; } mouseDown(target, event) { this._isMouseDown = true; this._dragStart = this._dragSensitivity > 0 ? { x: event.clientX, y: event.clientY } : undefined; return []; } mouseMove(target, event) { if (this._isMouseDown) { if (this._dragStart) { const dragDistance = sprotty_1.Point.maxDistance(this._dragStart, { x: event.clientX, y: event.clientY }); if (dragDistance < this._dragSensitivity) { return this.nonDraggingMouseMove(target, event); } } this._isMouseDrag = true; return this.draggingMouseMove(target, event); } return this.nonDraggingMouseMove(target, event); } draggingMouseMove(target, event) { return []; } nonDraggingMouseMove(target, event) { return []; } mouseUp(element, event) { this._isMouseDown = false; this._dragStart = undefined; if (this._isMouseDrag) { this._isMouseDrag = false; return this.draggingMouseUp(element, event); } return this.nonDraggingMouseUp(element, event); } nonDraggingMouseUp(element, event) { return []; } draggingMouseUp(element, event) { return []; } get isMouseDrag() { return this._isMouseDrag; } get isMouseDown() { return this._isMouseDown; } dispose() { this._isMouseDrag = false; this._isMouseDown = false; } } exports.DragAwareMouseListener = DragAwareMouseListener; //# sourceMappingURL=drag-aware-mouse-listener.js.map