From aa29c12b371ced1c4dbdeb66c7499bc501d8bcf2 Mon Sep 17 00:00:00 2001 From: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> Date: Wed, 12 Aug 2026 20:00:26 +0300 Subject: [PATCH] flush pending autosave before migrating the data folder save_documents debounces 400ms; migrateDataDir used to fire without waiting for it, so a save still in flight to the old folder could land after migrate had already moved documents.json away, silently recreating it in the abandoned folder and stranding the last edit. --- src/main.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 6102e50..a8a7a45 100644 --- a/src/main.ts +++ b/src/main.ts @@ -425,12 +425,15 @@ function bindDataDirSettings(): void { const picked = await chooseFolder(); if (!picked || picked === settings.dataDir) return; let strategy: "move" | "overwrite" | "use_existing" = "move"; - if (await dataDirHasDocuments(picked)) { - const ans = await askModal(t("folderConflict"), t("useExisting"), t("replaceMine")); - if (ans === null) return; - strategy = ans === "a" ? "use_existing" : "overwrite"; - } try { + if (await dataDirHasDocuments(picked)) { + const ans = await askModal(t("folderConflict"), t("useExisting"), t("replaceMine")); + if (ans === null) return; + strategy = ans === "a" ? "use_existing" : "overwrite"; + } + // a debounced save still aimed at the old folder would land after the + // migration moved documents.json away and silently strand the last edit + await flushAppData(); await migrateDataDir(settings.dataDir, picked, strategy); } catch (e) { console.warn("migrate failed", e);