mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-20 10:48:21 +01:00
v1.1.8 - Fix unsaved content lost when switching notes, fix blob image save race
This commit is contained in:
1 parent
0b5db1340c
commit
25d4cf7a9d
1 file changed
+8
-2
@@ -69,6 +69,7 @@
|
|||||||
let pendingContent = $state<string | null>(null);
|
let pendingContent = $state<string | null>(null);
|
||||||
let ignoreNextUpdate = false;
|
let ignoreNextUpdate = false;
|
||||||
let isLoadingNote = false;
|
let isLoadingNote = false;
|
||||||
|
let fixingBlobsPromise: Promise<void> = Promise.resolve();
|
||||||
let lastSourceMode = $sourceMode;
|
let lastSourceMode = $sourceMode;
|
||||||
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;
|
||||||
@@ -1056,6 +1057,8 @@
|
|||||||
|
|
||||||
const autoSave = debounce(async () => {
|
const autoSave = debounce(async () => {
|
||||||
if (!$activeNote || !$activeNotePath || !$editorDirty) return;
|
if (!$activeNote || !$activeNotePath || !$editorDirty) return;
|
||||||
|
// Wait for any pending blob→asset conversions to finish before serializing
|
||||||
|
await fixingBlobsPromise;
|
||||||
try {
|
try {
|
||||||
const body = $sourceMode
|
const body = $sourceMode
|
||||||
? restoreTitleH1(sourceContent)
|
? restoreTitleH1(sourceContent)
|
||||||
@@ -1075,6 +1078,7 @@
|
|||||||
|
|
||||||
export async function forceSave() {
|
export async function forceSave() {
|
||||||
if (!$activeNote || !$activeNotePath) return;
|
if (!$activeNote || !$activeNotePath) return;
|
||||||
|
await fixingBlobsPromise;
|
||||||
try {
|
try {
|
||||||
const body = $sourceMode ? restoreTitleH1(sourceContent) : editorToMarkdown();
|
const body = $sourceMode ? restoreTitleH1(sourceContent) : editorToMarkdown();
|
||||||
const trimmed = body.replace(/^#.*\n?/, '').trim();
|
const trimmed = body.replace(/^#.*\n?/, '').trim();
|
||||||
@@ -1415,6 +1419,7 @@
|
|||||||
}
|
}
|
||||||
case 'image': {
|
case 'image': {
|
||||||
const src = stripAssetSrc(node.attrs.src || '');
|
const src = stripAssetSrc(node.attrs.src || '');
|
||||||
|
if (!src) return ''; // Skip images with unresolved blob: URLs
|
||||||
const alt = node.attrs.alt || '';
|
const alt = node.attrs.alt || '';
|
||||||
const size = node.attrs['data-size'] || node.attrs.size || 'full';
|
const size = node.attrs['data-size'] || node.attrs.size || 'full';
|
||||||
const sizeSuffix = size && size !== 'full' ? `|size=${size}` : '';
|
const sizeSuffix = size && size !== 'full' ? `|size=${size}` : '';
|
||||||
@@ -1491,6 +1496,7 @@
|
|||||||
parts.push(text);
|
parts.push(text);
|
||||||
} else if (child.type.name === 'image') {
|
} else if (child.type.name === 'image') {
|
||||||
const src = stripAssetSrc(child.attrs.src || '');
|
const src = stripAssetSrc(child.attrs.src || '');
|
||||||
|
if (!src) return; // Skip images with unresolved blob: URLs
|
||||||
const alt = child.attrs.alt || '';
|
const alt = child.attrs.alt || '';
|
||||||
const size = child.attrs['data-size'] || child.attrs.size || 'full';
|
const size = child.attrs['data-size'] || child.attrs.size || 'full';
|
||||||
const sizeSuffix = size && size !== 'full' ? `|size=${size}` : '';
|
const sizeSuffix = size && size !== 'full' ? `|size=${size}` : '';
|
||||||
@@ -2127,9 +2133,9 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$editorDirty = true;
|
$editorDirty = true;
|
||||||
|
// Fix any blob: URLs from pasted web images BEFORE saving
|
||||||
|
fixingBlobsPromise = fixBlobImages();
|
||||||
autoSave();
|
autoSave();
|
||||||
// Fix any blob: URLs from pasted web images
|
|
||||||
fixBlobImages();
|
|
||||||
if (showOutline) updateOutline();
|
if (showOutline) updateOutline();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user