From bbfe968ff125b1344ad8d91ccb69cb18764215a9 Mon Sep 17 00:00:00 2001
From: th
Date: Sun, 12 Apr 2026 12:57:05 +0200
Subject: [PATCH] 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)
---
config.php | 2 +-
public/js/modules/editor.js | 4 ++--
public/js/modules/shortcuts.js | 15 +++++++++++++++
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/config.php b/config.php
index 189a4c4..30a2378 100644
--- a/config.php
+++ b/config.php
@@ -1,7 +1,7 @@
{
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);
diff --git a/public/js/modules/shortcuts.js b/public/js/modules/shortcuts.js
index 8960543..f0761d8 100644
--- a/public/js/modules/shortcuts.js
+++ b/public/js/modules/shortcuts.js
@@ -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;
|