From 0283826179cd3aec923053877f0742919c52e166 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Sat, 16 Mar 2024 18:44:36 +0300 Subject: [PATCH] prevent make alt key from opening main menu if it's used for brush size also --- .../canvas-zoom-and-pan/javascript/zoom.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index 6e61def21..ed2ef99b0 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -252,6 +252,7 @@ onUiLoaded(async() => { let isMoving = false; let mouseX, mouseY; let activeElement; + let interactedWithAltKey = false; const elements = Object.fromEntries( Object.keys(elementIDs).map(id => [ @@ -508,6 +509,10 @@ onUiLoaded(async() => { if (isModifierKey(e, hotkeysConfig.canvas_hotkey_zoom)) { e.preventDefault(); + if(hotkeysConfig.canvas_hotkey_zoom === "Alt"){ + interactedWithAltKey = true; + } + let zoomPosX, zoomPosY; let delta = 0.2; if (elemData[elemId].zoomLevel > 7) { @@ -800,6 +805,10 @@ onUiLoaded(async() => { if (isModifierKey(e, hotkeysConfig.canvas_hotkey_adjust)) { e.preventDefault(); + if(hotkeysConfig.canvas_hotkey_adjust === "Alt"){ + interactedWithAltKey = true; + } + // Increase or decrease brush size based on scroll direction adjustBrushSize(elemId, e.deltaY); } @@ -840,28 +849,16 @@ onUiLoaded(async() => { document.addEventListener("keyup", handleMoveKeyUp); - // Prevent firefox to open toolbar on pressing alt - let wasAltPressed = false; - - function handleAltKeyDown(e) { - if (!activeElement) return; - if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; - if (e.key === "Alt") { - wasAltPressed = true; - } else { - wasAltPressed = false; - } - } - + // Prevent firefox from opening main menu when alt is used as a hotkey for zoom or brush size function handleAltKeyUp(e) { - if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; - if (wasAltPressed || (activeElement && e.key === "Alt")) { - e.preventDefault(); + if (e.key !== "Alt" || !interactedWithAltKey) { + return; } - wasAltPressed = false; + + e.preventDefault(); + interactedWithAltKey = false; } - document.addEventListener("keydown", handleAltKeyDown); document.addEventListener("keyup", handleAltKeyUp);