From a435a8633fe0690fa850697b28b884df9b7f1258 Mon Sep 17 00:00:00 2001 From: Atreus-X Date: Wed, 30 Sep 2026 18:28:27 -0400 Subject: [PATCH] fix(library): stop PageUp/PageDown in the note editor from scrolling the block off screen Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01W6QMXXvRReaKxWk1JL5Et6 --- frontend/app/view/library/note-editor.tsx | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/frontend/app/view/library/note-editor.tsx b/frontend/app/view/library/note-editor.tsx index ec3ff20ce7..296b9e4e90 100644 --- a/frontend/app/view/library/note-editor.tsx +++ b/frontend/app/view/library/note-editor.tsx @@ -29,6 +29,26 @@ function refKey(r: CommandLibraryNoteRefData): string { return r.host ? `host:${r.host}` : `name:${r.name}`; } +// PageUp/PageDown in a textarea that can't scroll any further chains to the nearest scrollable ancestor, and +// an overflow:hidden ancestor (the block itself) still scrolls programmatically, pushing the block's top edge +// off screen with no way to scroll it back. Put any such ancestor back where it was. +function pinAncestorScroll(ta: HTMLTextAreaElement) { + const saved: [HTMLElement, number][] = []; + for (let el = ta.parentElement; el != null; el = el.parentElement) { + saved.push([el, el.scrollTop]); + } + const restore = () => { + for (const [el, top] of saved) { + if (el.scrollTop !== top) el.scrollTop = top; + } + }; + document.addEventListener("scroll", restore, true); + setTimeout(() => { + document.removeEventListener("scroll", restore, true); + restore(); + }, 250); +} + // Applies an edit through the browser's insertText so Ctrl+Z still works: only the changed middle // part is replaced, then the selection is set. Falls back to setting the value directly. function applyEdit(ta: HTMLTextAreaElement, edit: TextEdit, setValue: (v: string) => void) { @@ -174,6 +194,10 @@ export const NoteEditor = memo(({ noteRef, placeholder, compact }: NoteEditorPro const onKeyDown = (e: React.KeyboardEvent) => { const ta = e.currentTarget; const mod = e.ctrlKey || e.metaKey; + if (e.key === "PageUp" || e.key === "PageDown") { + pinAncestorScroll(ta); + return; + } if (mod && e.key.toLowerCase() === "s") { e.preventDefault(); save(false);