From f2801c9f1c4e48cc36e6ae29b0897332fcf34871 Mon Sep 17 00:00:00 2001 From: MassiveBox Date: Sun, 6 Apr 2025 12:21:25 +0200 Subject: [PATCH] Bug fix: save on no changes --- src/editorTab.ts | 14 ++++++++++++-- src/protyle.ts | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/editorTab.ts b/src/editorTab.ts index 8ebc0a0..001320d 100644 --- a/src/editorTab.ts +++ b/src/editorTab.ts @@ -45,8 +45,18 @@ async function saveCallback(editor: Editor, fileID: string, oldSyncID: string, s try { newSyncID = (await uploadAsset(fileID, SVG_MIME, svgElem.outerHTML)).syncID; - await replaceSyncID(fileID, oldSyncID, newSyncID); - await removeFile(DATA_PATH + IDsToAssetPath(fileID, oldSyncID)); + if(newSyncID != oldSyncID) { + const changed = await replaceSyncID(fileID, oldSyncID, newSyncID); + if(!changed) { + alert( + "Error replacing old sync ID with new one! You may need to manually replace the file path." + + "\nTry saving the drawing again. This is a bug, please open an issue as soon as you can." + + "\nIf your document doesn't show the drawing, you can recover it from the SiYuan workspace directory." + ); + return oldSyncID; + } + await removeFile(DATA_PATH + IDsToAssetPath(fileID, oldSyncID)); + } saveButton.setDisabled(true); setTimeout(() => { // @todo improve save button feedback saveButton.setDisabled(false); diff --git a/src/protyle.ts b/src/protyle.ts index 292221c..b3b8905 100644 --- a/src/protyle.ts +++ b/src/protyle.ts @@ -50,6 +50,7 @@ export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID const search = encodeURI(IDsToAssetPath(fileID, oldSyncID)); // the API uses URI-encoded // find blocks containing that image const blocks = await findImageBlocks(search); + if(blocks.length === 0) return false; for(const block of blocks) { @@ -62,8 +63,11 @@ export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID for(const source of sources) { const newSource = IDsToAssetPath(fileID, newSyncID); - await replaceBlockContent(block.id, source, newSource); + const changed = await replaceBlockContent(block.id, source, newSource); + if(!changed) return false } + } + return true; }