fix: keep the style-manager selection across edits
The cursor-follow effect read the sheet and the editor state, so every edit (sheet replaced + FORCE_PAGE_RECALC) re-ran it and reset all four tabs' selections to the cursor's style or the first entry. Untrack the body; only the dialog opening triggers it now.
This commit is contained in:
1 parent
48f44f3dcd
commit
108983fa86
1 file changed
+11
-5
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import type { Editor } from '@tiptap/core';
|
||||
import { t } from '../i18n/i18n.svelte';
|
||||
import {
|
||||
@@ -196,12 +197,17 @@
|
||||
});
|
||||
|
||||
// Follow the cursor's style when the dialog opens (LibreOffice preselects it too).
|
||||
// Untracked past the `open` guard: an edit replaces the sheet and pokes the editor
|
||||
// (FORCE_PAGE_RECALC), and either would otherwise reset the selection mid-session.
|
||||
$effect(() => {
|
||||
if (!open || !editor) return;
|
||||
selected = blockStyleName(editor.state.selection.$from.parent as never);
|
||||
selectedChar = activeCharacterStyle(editor.state as never) ?? Object.keys(sheet.character)[0] ?? '';
|
||||
selectedTable = activeTableStyle(editor.state as never) ?? Object.keys(sheet.table ?? {})[0] ?? '';
|
||||
selectedList = listStyleNameAt(editor.state as never) ?? Object.keys(sheet.list ?? {})[0] ?? '';
|
||||
if (!open) return;
|
||||
untrack(() => {
|
||||
if (!editor) return;
|
||||
selected = blockStyleName(editor.state.selection.$from.parent as never);
|
||||
selectedChar = activeCharacterStyle(editor.state as never) ?? Object.keys(sheet.character)[0] ?? '';
|
||||
selectedTable = activeTableStyle(editor.state as never) ?? Object.keys(sheet.table ?? {})[0] ?? '';
|
||||
selectedList = listStyleNameAt(editor.state as never) ?? Object.keys(sheet.list ?? {})[0] ?? '';
|
||||
});
|
||||
});
|
||||
|
||||
// An undefined patch value clears the style's own property, so it inherits again.
|
||||
|
||||
Reference in new issue
Block a user