diff --git a/src/main.js b/src/main.js index aa5ccf5..42b54fb 100644 --- a/src/main.js +++ b/src/main.js @@ -119,6 +119,7 @@ function handleKeys(event, key, up) { if (lowercaseKey === "x") return onKeyX(up) if (lowercaseKey === "shift") return onKeyShift(up) if (lowercaseKey === "space") return onKeySpace(up); + if (lowercaseKey === "escape") return onKeyEscape(up); return false } @@ -160,13 +161,22 @@ function onKeySpace(up) { if (!up) { if (swapSpacebarRightClick) - ruler.dragRulerDeleteWaypoint(); + ruler.dragRulerAbortDrag(); else startDragRuler.call(ruler.draggedEntity, options); } return true; } +function onKeyEscape(up) { + const ruler = canvas.controls.ruler; + if (!ruler.draggedEntity) + return false; + if (!up) + ruler.dragRulerAbortDrag(); + return true; +} + function onEntityLeftDragStart(event) { const isToken = this instanceof Token; const ruler = canvas.controls.ruler diff --git a/src/ruler.js b/src/ruler.js index 7d9f4ef..8688a6b 100644 --- a/src/ruler.js +++ b/src/ruler.js @@ -110,19 +110,23 @@ export class DragRulerRuler extends Ruler { game.user.broadcastActivity({ruler: this}); } else { - const token = this.draggedEntity; - this._endMeasurement(); - - // Deactivate the drag workflow in mouse - token.mouseInteractionManager._deactivateDragEvents(); - token.mouseInteractionManager.state = token.mouseInteractionManager.states.HOVER; - - // This will cancel the current drag operation - // Pass in a fake event that hopefully is enough to allow other modules to function - token._onDragLeftCancel(event); + this.dragRulerAbortDrag(event); } } + dragRulerAbortDrag(event={preventDefault: () => {return}}) { + const token = this.draggedEntity; + this._endMeasurement(); + + // Deactivate the drag workflow in mouse + token.mouseInteractionManager._deactivateDragEvents(); + token.mouseInteractionManager.state = token.mouseInteractionManager.states.HOVER; + + // This will cancel the current drag operation + // Pass in a fake event that hopefully is enough to allow other modules to function + token._onDragLeftCancel(event); + } + async dragRulerRecalculate(tokenIds) { if (this._state !== Ruler.STATES.MEASURING) return;