Skip to content

Commit 62ccd6f

Browse files
committed
fix false hotkey triggers
1 parent babf2b9 commit 62ccd6f

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/wplace-bot-manager.user.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
const STORAGE_KEY = 'wplace-bot-scripts-v1';
2020
const BASE_URL_KEY = 'wplace-bot-base-url';
2121
const HOST_ID = 'wplace-bot-launcher-host';
22-
const POPUP_NAME = 'wplace-bot-switcher';
2322
const TARGET_NAME_KEY = 'wplace-target-name';
24-
const POPUP_W = 460;
25-
const POPUP_H = 620;
2623

2724
// Add hotkey to open manager (Ctrl+Shift+M)
2825
document.addEventListener('keydown', function (e) {
@@ -595,19 +592,28 @@
595592

596593
// Keyboard for inline panel
597594
function onKeyDown(e) {
598-
const tag = (e.target && e.target.tagName) || '';
599-
if (
600-
tag === 'INPUT' ||
601-
tag === 'TEXTAREA' ||
602-
(e.target && e.target.isContentEditable)
603-
) {
604-
return;
605-
}
595+
// Check if we're dealing with shadow DOM retargeting
596+
const actualTarget = e.composedPath ? e.composedPath()[0] : e.target;
597+
const actualTag = (actualTarget && actualTarget.tagName || '').toUpperCase();
598+
599+
// Always allow ESC to close
606600
if (e.key === 'Escape') {
607601
close();
608602
e.preventDefault();
609603
return;
610604
}
605+
606+
// Don't trigger hotkeys when typing in input fields anywhere
607+
// Use actualTag to check the real target element
608+
if (
609+
actualTag === 'INPUT' ||
610+
actualTag === 'TEXTAREA' ||
611+
(actualTarget && actualTarget.isContentEditable)
612+
) {
613+
return;
614+
}
615+
616+
// Only handle numeric hotkeys when not in an input field
611617
if (e.key >= '0' && e.key <= '9') {
612618
const items = sortedScripts();
613619
const idx = e.key === '0' ? 9 : Number(e.key) - 1;
@@ -749,4 +755,4 @@
749755
}, 1000);
750756
}
751757
}
752-
})();
758+
})();

0 commit comments

Comments
 (0)