fix(reader): stop page-turn and zoom shortcuts while typing in form fields
handleKeydown computed a 'typing' guard for the event target but only applied it to the drawer-shortcut block (t/s/b/?//). The vi-style page turns (h/l), arrows, and zoom keys (+/−/0) fired regardless, so typing into the note textarea hijacked the keys: 'Wh' turned back a page on the h, arrows moved pages instead of the caret, and digits/minus zoomed. Return early for INPUT/SELECT/TEXTAREA/contentEditable targets, keeping Escape live so popovers and drawers stay dismissable from the keyboard mid-note. Covers the selection-popover note field, the notes drawer textarea, bookmark rename, and the search box. The now-unreachable '!typing' condition on the shortcut block is dropped.
This commit is contained in:
@@ -2493,11 +2493,18 @@ document.addEventListener("alpine:init", () => {
|
|||||||
},
|
},
|
||||||
handleKeydown(event: KeyboardEvent) {
|
handleKeydown(event: KeyboardEvent) {
|
||||||
const k = event.key;
|
const k = event.key;
|
||||||
// Never hijack keys while the user is typing in a form control.
|
// Never hijack keys while the user is typing in a form control: the
|
||||||
const tag = (event.target as HTMLElement)?.tagName;
|
// field must receive h/l page turns, +/− zoom, and caret arrows.
|
||||||
|
// Escape stays live so popovers/drawers can still be dismissed from
|
||||||
|
// the keyboard even mid-note.
|
||||||
|
const t = event.target as HTMLElement | null;
|
||||||
const typing =
|
const typing =
|
||||||
tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA";
|
t?.tagName === "INPUT" ||
|
||||||
|
t?.tagName === "SELECT" ||
|
||||||
|
t?.tagName === "TEXTAREA" ||
|
||||||
|
!!t?.isContentEditable;
|
||||||
this.pokeChrome();
|
this.pokeChrome();
|
||||||
|
if (typing && k !== "Escape") return;
|
||||||
if (k === "ArrowLeft" || k === "h") {
|
if (k === "ArrowLeft" || k === "h") {
|
||||||
if (event.altKey) {
|
if (event.altKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -2526,7 +2533,7 @@ document.addEventListener("alpine:init", () => {
|
|||||||
} else if (k === "F1") {
|
} else if (k === "F1") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.toggleHelp();
|
this.toggleHelp();
|
||||||
} else if (!typing) {
|
} else {
|
||||||
if (k === "t") this.toggleTOC();
|
if (k === "t") this.toggleTOC();
|
||||||
else if (k === "s") this.toggleSettings();
|
else if (k === "s") this.toggleSettings();
|
||||||
else if (k === "b") this.addBookmark();
|
else if (k === "b") this.addBookmark();
|
||||||
|
|||||||
Reference in New Issue
Block a user