From 6f51e0555376cff9f185cb4f1dde8537bfec92af Mon Sep 17 00:00:00 2001 From: Andray Date: Fri, 15 Mar 2024 12:01:43 +0400 Subject: [PATCH 1/5] prevent alt menu for firefox --- .../canvas-zoom-and-pan/javascript/zoom.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index 64e7a638a4c..aa27ac15752 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -966,3 +966,26 @@ onUiLoaded(async() => { // Add integration with Inpaint Anything // applyZoomAndPanIntegration("None", ["#ia_sam_image", "#ia_sel_mask"]); }); + + +onUiLoaded(function() { + let isAltPressed = false; + + function handleAltKeyDown(e) { + if (e.code === "AltLeft" || e.code === "AltRight") { + isAltPressed = true; + } else { + isAltPressed = false; + } + } + + function handleAltKeyUp(e) { + if (isAltPressed) { + e.preventDefault(); + } + isAltPressed = false; + } + + document.addEventListener("keydown", handleAltKeyDown); + document.addEventListener("keyup", handleAltKeyUp); +}); From 79514e5b8e112c47128f3da506267e8540219097 Mon Sep 17 00:00:00 2001 From: Andray Date: Sat, 16 Mar 2024 16:06:21 +0400 Subject: [PATCH 2/5] prevent defaults for alt only if mouse inside image --- .../canvas-zoom-and-pan/javascript/zoom.js | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index aa27ac15752..63900025f39 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -839,6 +839,31 @@ onUiLoaded(async() => { document.addEventListener("keydown", handleMoveKeyDown); document.addEventListener("keyup", handleMoveKeyUp); + // Prevent firefox to open toolbar on pressing alt + if (hotkeysConfig.canvas_hotkey_zoom === "Alt") { + let isAltPressed = false; + + function handleAltKeyDown(e) { + if (!activeElement) return; + if (e.code === "AltLeft" || e.code === "AltRight") { + isAltPressed = true; + } else { + isAltPressed = false; + } + } + + function handleAltKeyUp(e) { + if (isAltPressed) { + e.preventDefault(); + } + isAltPressed = false; + } + + document.addEventListener("keydown", handleAltKeyDown); + document.addEventListener("keyup", handleAltKeyUp); + } + + // Detect zoom level and update the pan speed. function updatePanPosition(movementX, movementY) { let panSpeed = 2; @@ -966,26 +991,3 @@ onUiLoaded(async() => { // Add integration with Inpaint Anything // applyZoomAndPanIntegration("None", ["#ia_sam_image", "#ia_sel_mask"]); }); - - -onUiLoaded(function() { - let isAltPressed = false; - - function handleAltKeyDown(e) { - if (e.code === "AltLeft" || e.code === "AltRight") { - isAltPressed = true; - } else { - isAltPressed = false; - } - } - - function handleAltKeyUp(e) { - if (isAltPressed) { - e.preventDefault(); - } - isAltPressed = false; - } - - document.addEventListener("keydown", handleAltKeyDown); - document.addEventListener("keyup", handleAltKeyUp); -}); From 9142ce8188cc0d7b8847df0c2f11ab47a0b13a50 Mon Sep 17 00:00:00 2001 From: Andray Date: Sat, 16 Mar 2024 16:14:57 +0400 Subject: [PATCH 3/5] fix linter and do not require reload page if option was changed --- .../canvas-zoom-and-pan/javascript/zoom.js | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index 63900025f39..a575862dfdd 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -839,30 +839,31 @@ onUiLoaded(async() => { document.addEventListener("keydown", handleMoveKeyDown); document.addEventListener("keyup", handleMoveKeyUp); - // Prevent firefox to open toolbar on pressing alt - if (hotkeysConfig.canvas_hotkey_zoom === "Alt") { - let isAltPressed = false; - function handleAltKeyDown(e) { - if (!activeElement) return; - if (e.code === "AltLeft" || e.code === "AltRight") { - isAltPressed = true; - } else { - isAltPressed = false; - } - } + // Prevent firefox to open toolbar on pressing alt + let isAltPressed = false; - function handleAltKeyUp(e) { - if (isAltPressed) { - e.preventDefault(); - } + function handleAltKeyDown(e) { + if (!activeElement) return; + if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; + if (e.code === "AltLeft" || e.code === "AltRight") { + isAltPressed = true; + } else { isAltPressed = false; } + } - document.addEventListener("keydown", handleAltKeyDown); - document.addEventListener("keyup", handleAltKeyUp); + function handleAltKeyUp(e) { + if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; + if (isAltPressed) { + e.preventDefault(); + } + isAltPressed = false; } + document.addEventListener("keydown", handleAltKeyDown); + document.addEventListener("keyup", handleAltKeyUp); + // Detect zoom level and update the pan speed. function updatePanPosition(movementX, movementY) { From eb2ea8df1de2aaaab8a1ed069b34ca7385e30af2 Mon Sep 17 00:00:00 2001 From: Andray Date: Sat, 16 Mar 2024 17:42:25 +0400 Subject: [PATCH 4/5] check e.key in up event --- .../canvas-zoom-and-pan/javascript/zoom.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index a575862dfdd..dfd7b17a272 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -841,24 +841,24 @@ onUiLoaded(async() => { // Prevent firefox to open toolbar on pressing alt - let isAltPressed = false; + let wasAltPressed = false; function handleAltKeyDown(e) { if (!activeElement) return; if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; if (e.code === "AltLeft" || e.code === "AltRight") { - isAltPressed = true; + wasAltPressed = true; } else { - isAltPressed = false; + wasAltPressed = false; } } function handleAltKeyUp(e) { if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; - if (isAltPressed) { + if (wasAltPressed || (activeElement && e.key === "Alt")) { e.preventDefault(); } - isAltPressed = false; + wasAltPressed = false; } document.addEventListener("keydown", handleAltKeyDown); From 7598a92436be66f5ba63a9234ba8cdbcbc3cc662 Mon Sep 17 00:00:00 2001 From: Andray Date: Sat, 16 Mar 2024 17:49:05 +0400 Subject: [PATCH 5/5] use e.key instead of e.code --- extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index dfd7b17a272..c6b463fd4a0 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -846,7 +846,7 @@ onUiLoaded(async() => { function handleAltKeyDown(e) { if (!activeElement) return; if (hotkeysConfig.canvas_hotkey_zoom !== "Alt") return; - if (e.code === "AltLeft" || e.code === "AltRight") { + if (e.key === "Alt") { wasAltPressed = true; } else { wasAltPressed = false;