fix: suppress shortcuts when typing in input fields
Shortcut dispatcher now skips non-modifier keys when focus is in an editable field. Editor find bar ESC stops propagation to close bar before modal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d1b26e625a
commit
bbfe968ff1
3 files changed
+18
-3
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
define('APP_NAME', 'hyprcrd');
|
||||
define('APP_VERSION', '1.0.0');
|
||||
define('APP_VERSION', '1.0.1');
|
||||
|
||||
// Database path — writable directory, outside webroot
|
||||
define('DB_PATH', __DIR__ . '/data/hyprcrd.db');
|
||||
|
||||
@@ -1080,11 +1080,11 @@ function replaceAll() {
|
||||
findInput?.addEventListener('input', runFind);
|
||||
findInput?.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); e.shiftKey ? findPrev() : findNext(); }
|
||||
if (e.key === 'Escape') { e.preventDefault(); closeFindBar(); }
|
||||
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeFindBar(); }
|
||||
});
|
||||
replInput?.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); replaceOne(); }
|
||||
if (e.key === 'Escape') { e.preventDefault(); closeFindBar(); }
|
||||
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeFindBar(); }
|
||||
});
|
||||
$('find-next')?.addEventListener('click', findNext);
|
||||
$('find-prev')?.addEventListener('click', findPrev);
|
||||
|
||||
@@ -87,7 +87,18 @@ export const guards = {
|
||||
|
||||
// ── Dispatcher ──
|
||||
|
||||
function isEditableTarget() {
|
||||
const el = document.activeElement;
|
||||
if (!el) return false;
|
||||
const tag = el.tagName;
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true;
|
||||
if (el.isContentEditable) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
const inEditable = isEditableTarget();
|
||||
|
||||
for (const s of registry) {
|
||||
// Key match
|
||||
let matched;
|
||||
@@ -102,6 +113,10 @@ document.addEventListener('keydown', (e) => {
|
||||
}
|
||||
if (!matched) continue;
|
||||
|
||||
// Suppress non-modifier shortcuts when focus is in an editable field
|
||||
// (except Escape which should always close overlays)
|
||||
if (inEditable && !s.ctrl && !s.alt && !s.match && e.key !== 'Escape') continue;
|
||||
|
||||
// Guard
|
||||
if (s.guard && !s.guard()) continue;
|
||||
|
||||
|
||||
Reference in new issue
Block a user