Skip to content

Commit

Permalink
prevent make alt key from opening main menu if it's used for brush si…
Browse files Browse the repository at this point in the history
…ze also
  • Loading branch information
AUTOMATIC1111 committed Mar 16, 2024
1 parent 2f9d1c3 commit 0283826
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [
Expand Down Expand Up @@ -508,6 +509,10 @@ onUiLoaded(async() => {
if (isModifierKey(e, hotkeysConfig.canvas_hotkey_zoom)) {
e.preventDefault();

if(hotkeysConfig.canvas_hotkey_zoom === "Alt"){

Check failure on line 512 in extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js

View workflow job for this annotation

GitHub Actions / eslint

Expected space(s) after "if"

Check failure on line 512 in extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js

View workflow job for this annotation

GitHub Actions / eslint

Missing space before opening brace
interactedWithAltKey = true;
}

let zoomPosX, zoomPosY;
let delta = 0.2;
if (elemData[elemId].zoomLevel > 7) {
Expand Down Expand Up @@ -800,6 +805,10 @@ onUiLoaded(async() => {
if (isModifierKey(e, hotkeysConfig.canvas_hotkey_adjust)) {
e.preventDefault();

if(hotkeysConfig.canvas_hotkey_adjust === "Alt"){

Check failure on line 808 in extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js

View workflow job for this annotation

GitHub Actions / eslint

Expected space(s) after "if"

Check failure on line 808 in extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js

View workflow job for this annotation

GitHub Actions / eslint

Missing space before opening brace
interactedWithAltKey = true;
}

// Increase or decrease brush size based on scroll direction
adjustBrushSize(elemId, e.deltaY);
}
Expand Down Expand Up @@ -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);


Expand Down

0 comments on commit 0283826

Please sign in to comment.