Abort the drag when pressing ESC (resolves #73)

This commit is contained in:
Manuel Vögele
2021-08-02 15:51:12 +02:00
parent f1a153a2eb
commit 63b13cbb34
2 changed files with 25 additions and 11 deletions
+11 -1
View File
@@ -119,6 +119,7 @@ function handleKeys(event, key, up) {
if (lowercaseKey === "x") return onKeyX(up) if (lowercaseKey === "x") return onKeyX(up)
if (lowercaseKey === "shift") return onKeyShift(up) if (lowercaseKey === "shift") return onKeyShift(up)
if (lowercaseKey === "space") return onKeySpace(up); if (lowercaseKey === "space") return onKeySpace(up);
if (lowercaseKey === "escape") return onKeyEscape(up);
return false return false
} }
@@ -160,13 +161,22 @@ function onKeySpace(up) {
if (!up) { if (!up) {
if (swapSpacebarRightClick) if (swapSpacebarRightClick)
ruler.dragRulerDeleteWaypoint(); ruler.dragRulerAbortDrag();
else else
startDragRuler.call(ruler.draggedEntity, options); startDragRuler.call(ruler.draggedEntity, options);
} }
return true; return true;
} }
function onKeyEscape(up) {
const ruler = canvas.controls.ruler;
if (!ruler.draggedEntity)
return false;
if (!up)
ruler.dragRulerAbortDrag();
return true;
}
function onEntityLeftDragStart(event) { function onEntityLeftDragStart(event) {
const isToken = this instanceof Token; const isToken = this instanceof Token;
const ruler = canvas.controls.ruler const ruler = canvas.controls.ruler
+14 -10
View File
@@ -110,19 +110,23 @@ export class DragRulerRuler extends Ruler {
game.user.broadcastActivity({ruler: this}); game.user.broadcastActivity({ruler: this});
} }
else { else {
const token = this.draggedEntity; this.dragRulerAbortDrag(event);
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);
} }
} }
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) { async dragRulerRecalculate(tokenIds) {
if (this._state !== Ruler.STATES.MEASURING) if (this._state !== Ruler.STATES.MEASURING)
return; return;