diff --git a/CHANGELOG.md b/CHANGELOG.md index f4c36bd..60f5f20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar - The module can now be configured use a fixed color instead of the player color for the first speed range - On gridless maps the ruler will now change it's color to indicate the different speed ranges +- As an alternative to right click (or spacebar, if you have swapped right and spacebar behavior) waypoints can now also be deleted with the `X` key ### Bugfixes - Disabling snap to grid with shift now works as expected diff --git a/src/main.js b/src/main.js index 29adb4a..7efd3b8 100644 --- a/src/main.js +++ b/src/main.js @@ -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}