From a1404062c57c944627ec8aaf818b87622a40b241 Mon Sep 17 00:00:00 2001 From: MF Date: Mon, 15 Jun 2026 18:46:44 +0200 Subject: [PATCH] Fix collapsible section title focus (#112) Fixes keyboard navigation after creating a collapsible section: pressing Enter or Tab from the section title now moves the editor selection into the section body (`Start writing...`) instead of leaving the cursor in the title. Validation: `COREPACK_ENABLE_AUTO_PIN=0 pnpm build`. Reviewed-on: https://codeberg.org/ArkHost/HelixNotes/pulls/112 --- src/lib/components/Editor.svelte | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index 06c829a..b3a40b5 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -30,7 +30,7 @@ import katex from 'katex'; import 'katex/dist/katex.min.css'; import { Extension, Node as TiptapNode, Mark as TiptapMark, mergeAttributes } from '@tiptap/core'; - import { Plugin, PluginKey, EditorState, TextSelection } from '@tiptap/pm/state'; + import { Plugin, PluginKey, EditorState, Selection, TextSelection } from '@tiptap/pm/state'; import { Decoration, DecorationSet } from '@tiptap/pm/view'; import { DOMSerializer } from '@tiptap/pm/model'; import { convertFileSrc } from '@tauri-apps/api/core'; @@ -3065,10 +3065,11 @@ if (detailsEl) openDetailsEl(detailsEl); // Sync open state into document + move cursor (single transaction) const detailsPos = from.before(detailsDepth); - view.dispatch(view.state.tr - .setNodeMarkup(detailsPos, undefined, { open: true }) - .setSelection(TextSelection.create(view.state.doc, detailsContentPos)) - ); + const tr = view.state.tr.setNodeMarkup(detailsPos, undefined, { open: true }); + const mappedContentPos = tr.mapping.map(detailsContentPos); + tr.setSelection(Selection.near(tr.doc.resolve(mappedContentPos), 1)); + view.dispatch(tr.scrollIntoView()); + view.focus(); return true; } }