Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Scroll the document to the top after the title-Enter newline
Elian Doran5c8bbb40cf5f
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsxindex 69eaa01a97..6c5d960f16 100644--- a/apps/client/src/widgets/type_widgets/code/Code.tsx+++ b/apps/client/src/widgets/type_widgets/code/Code.tsx@@ -234,6 +234,10 @@ export function CodeEditor({ parentComponent, ntxId, containerRef: externalContaif (!editor) return;if (insertNewlineAtTop) {editor.insertBlankLineAtTop();+ // The code editor itself is `overflow: hidden`; the surrounding `.scrolling-container`+ // scrolls (together with the inline title), so CodeMirror's own scrollIntoView can't+ // reveal the new top line. Scroll that container to the top once the line has rendered.+ requestAnimationFrame(() => editor.dom.closest(".scrolling-container")?.scrollTo({ top: 0 }));}editor.focus();});diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsxindex f43e6f0228..07dca728cf 100644--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx@@ -315,6 +315,11 @@ function placeCursorInNewTopParagraph(editor: CKTextEditor) {writer.insert(paragraph, root, 0);writer.setSelection(paragraph, "in");});++ // The scrolling container scrolls, not the editor itself, and the inline title may have scrolled+ // out of view (e.g. the cursor was at the bottom of a long note), so the selection change alone+ // won't move the viewport. Explicitly reveal the new top paragraph once it has rendered.+ requestAnimationFrame(() => editor.editing.view.scrollToTheSelection());}function useTemplates() {diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex 1956704c0c..cff57c5a8b 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -289,7 +289,9 @@ export default class CodeMirror extends EditorView {const firstLineEmpty = this.state.doc.line(1).length === 0;this.dispatch({...(firstLineEmpty ? {} : { changes: { from: 0, insert: "\n" } }),- selection: EditorSelection.cursor(0)+ selection: EditorSelection.cursor(0),+ // Reveal the new top line — the cursor may have been at the bottom of a long note.+ scrollIntoView: true});}