mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-23 23:35:57 +02:00
Fix editor not rendering on every other source mode switch
This commit is contained in:
@@ -78,7 +78,6 @@
|
|||||||
let fixingBlobsPromise: Promise<void> = Promise.resolve();
|
let fixingBlobsPromise: Promise<void> = Promise.resolve();
|
||||||
let hasPendingBlobs = false;
|
let hasPendingBlobs = false;
|
||||||
let lastSourceMode = $sourceMode;
|
let lastSourceMode = $sourceMode;
|
||||||
let sourceSwapPending = false;
|
|
||||||
let linkContextMenu = $state<{ x: number; y: number; href: string; anchor: HTMLAnchorElement } | null>(null);
|
let linkContextMenu = $state<{ x: number; y: number; href: string; anchor: HTMLAnchorElement } | null>(null);
|
||||||
let titleWasStripped = false;
|
let titleWasStripped = false;
|
||||||
let strippedTitle = '';
|
let strippedTitle = '';
|
||||||
@@ -3328,11 +3327,11 @@
|
|||||||
// When editorElement appears in DOM, initialize TipTap.
|
// When editorElement appears in DOM, initialize TipTap.
|
||||||
// On mobile, pre-create editor with empty content so first note load is fast.
|
// On mobile, pre-create editor with empty content so first note load is fast.
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (editorElement && !editor && !sourceSwapPending) {
|
if (editorElement && !editor) {
|
||||||
if (pendingContent !== null) {
|
if (pendingContent !== null) {
|
||||||
createEditor(pendingContent);
|
createEditor(pendingContent);
|
||||||
pendingContent = null;
|
pendingContent = null;
|
||||||
} else if (isMobile) {
|
} else if (isMobile && !lastSourceMode) {
|
||||||
createEditor('');
|
createEditor('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3393,9 +3392,6 @@
|
|||||||
|
|
||||||
function createEditor(content: string) {
|
function createEditor(content: string) {
|
||||||
if (!editorElement) return;
|
if (!editorElement) return;
|
||||||
// Don't call destroyEditor here — it sets editorReady=false which
|
|
||||||
// triggers reactivity and races with the tick().then() in the
|
|
||||||
// source-mode swap. Just destroy the editor instance directly.
|
|
||||||
if (editor) {
|
if (editor) {
|
||||||
editor.destroy();
|
editor.destroy();
|
||||||
editor = null;
|
editor = null;
|
||||||
@@ -4640,15 +4636,14 @@
|
|||||||
editor.commands.setContent(markdownToHtml(content));
|
editor.commands.setContent(markdownToHtml(content));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Desktop: destroy old editor, wait for DOM swap, then recreate.
|
// Desktop: destroy old editor (its DOM element is gone),
|
||||||
sourceSwapPending = true;
|
// wait for DOM to swap textarea→div, then create editor on new element.
|
||||||
destroyEditor();
|
destroyEditor();
|
||||||
const content = sourceContent || ($activeNote?.content ?? '');
|
const content = sourceContent || ($activeNote?.content ?? '');
|
||||||
tick().then(() => {
|
tick().then(() => {
|
||||||
if (editorElement && !editor) {
|
if (editorElement && !editor) {
|
||||||
createEditor(content);
|
createEditor(content);
|
||||||
}
|
}
|
||||||
sourceSwapPending = false;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user