Allow deleting of waypoints with the 'X' key (resolves #14)

This commit is contained in:
Manuel Vögele
2021-02-08 18:29:49 +01:00
parent 4bd1473310
commit 2b66b43c55
2 changed files with 27 additions and 0 deletions
+26
View File
@@ -8,6 +8,7 @@ Hooks.once("init", () => {
registerSettings()
hookTokenDragHandlers()
hookRulerFunctions()
hookKeyboardManagerFunctions()
patchRulerHighlightMeasurement()
availableSpeedProviders["native"] = nativeSpeedProvider
@@ -100,6 +101,31 @@ function hookRulerFunctions() {
}
}
function hookKeyboardManagerFunctions() {
const originalHandleKeys = KeyboardManager.prototype._handleKeys
KeyboardManager.prototype._handleKeys = function (event, key, up) {
const eventHandled = handleKeys.call(this, event, key, up)
if (!eventHandled)
originalHandleKeys.call(this, event, key, up)
}
}
function handleKeys(event, key, up) {
if (up || event.repeat || this.hasFocus)
return false
if (key.toLowerCase() === "x") return onKeyDownX()
return false
}
function onKeyDownX() {
if (!canvas.controls.ruler.isDragRuler)
return false
deleteWaypoint()
return true
}
function onTokenLeftDragStart(event) {
canvas.controls.ruler.draggedToken = this
const tokenCenter = {x: this.x + canvas.grid.grid.w / 2, y: this.y + canvas.grid.grid.h / 2}