mirror of
https://github.com/9x/sheetmusictrainer.git
synced 2026-11-03 22:03:54 +01:00
Restore text-entry gate for keyboard shortcuts (cleanup)
This commit is contained in:
16
src/App.tsx
16
src/App.tsx
@@ -123,24 +123,24 @@ function App() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
const target = e.target as HTMLElement | null;
|
const target = e.target as HTMLElement | null;
|
||||||
const onInteractive =
|
// Text inputs / selects keep their native keys — shortcuts must not
|
||||||
|
// fire while typing. FOCUSED BUTTONS however stay eligible: after a
|
||||||
|
// click the button keeps focus, and gating there made N/R/P/L
|
||||||
|
// silently dead until the user clicked elsewhere. Space/Enter on a
|
||||||
|
// focused button activate it natively (guarded below), so no
|
||||||
|
// double-fire.
|
||||||
|
const onTextEntry =
|
||||||
target instanceof HTMLInputElement ||
|
target instanceof HTMLInputElement ||
|
||||||
target instanceof HTMLTextAreaElement ||
|
target instanceof HTMLTextAreaElement ||
|
||||||
target instanceof HTMLSelectElement ||
|
target instanceof HTMLSelectElement ||
|
||||||
!!target?.isContentEditable;
|
!!target?.isContentEditable;
|
||||||
|
if (onTextEntry) return;
|
||||||
|
|
||||||
if (e.code === 'Escape') {
|
if (e.code === 'Escape') {
|
||||||
if (showHelp) setShowHelp(false);
|
if (showHelp) setShowHelp(false);
|
||||||
else if (settings.zenMode) setSettings(s => ({ ...s, zenMode: false }));
|
else if (settings.zenMode) setSettings(s => ({ ...s, zenMode: false }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Text inputs and selects must keep their native keys — shortcuts are
|
|
||||||
// for typing-free contexts. FOCUSED BUTTONS however stay eligible:
|
|
||||||
// after a click the button keeps focus, and blocking global shortcuts
|
|
||||||
// there made N/R/P/L silently dead until the user clicked elsewhere.
|
|
||||||
// Space/Enter on a focused button activate it natively and return below,
|
|
||||||
// so no double-fire.
|
|
||||||
|
|
||||||
// Prevent default for space to stop scrolling (Space on a focused
|
// Prevent default for space to stop scrolling (Space on a focused
|
||||||
// button activates it natively — preventDefault only applies when the
|
// button activates it natively — preventDefault only applies when the
|
||||||
// focus is on the body, where the shortcut below takes over).
|
// focus is on the body, where the shortcut below takes over).
|
||||||
|
|||||||
Reference in New Issue
Block a user