diff --git a/src/components/StackedNote.vue b/src/components/StackedNote.vue index bc8cf31..59345b6 100644 --- a/src/components/StackedNote.vue +++ b/src/components/StackedNote.vue @@ -205,7 +205,8 @@ const performSave = async (overrideSha?: string) => { } await saveCacheNote(encodeUTF8ToBase64(rawContent.value), { - editedSha: newSha + editedSha: newSha, + path: path.value }) initialRawContent.value = rawContent.value } diff --git a/src/modules/repo/store/userRepo.store.spec.ts b/src/modules/repo/store/userRepo.store.spec.ts index b5b505d..30b4b9f 100644 --- a/src/modules/repo/store/userRepo.store.spec.ts +++ b/src/modules/repo/store/userRepo.store.spec.ts @@ -105,6 +105,18 @@ describe("userRepo store — synchronous mutations", () => { expect(vi.mocked(data.update)).not.toHaveBeenCalled() }) + it("addFile replaces the entry at the same path when content (sha) changed", () => { + const store = useUserRepoStore() + store.user = "alice" + store.repo = "notes" + store.files = [{ sha: "old", path: "a.md", type: "blob" }] as never + + store.addFile({ sha: "new", path: "a.md", type: "blob" } as never) + + expect(store.files).toEqual([{ sha: "new", path: "a.md", type: "blob" }]) + expect(vi.mocked(data.update)).toHaveBeenCalled() + }) + it("setFontFamily initializes userSettings when absent and persists to localStorage", () => { const store = useUserRepoStore() store.user = "alice" diff --git a/src/modules/repo/store/userRepo.store.ts b/src/modules/repo/store/userRepo.store.ts index 7171d15..7a6e1de 100644 --- a/src/modules/repo/store/userRepo.store.ts +++ b/src/modules/repo/store/userRepo.store.ts @@ -233,7 +233,9 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", { `${this.user}-${this.repo}` ) const newFiles = [ - ...toRaw(this.files).filter((f) => f.sha !== file.sha), + ...toRaw(this.files).filter( + (f) => f.sha !== file.sha && f.path !== file.path + ), toRaw(file) ] data.update({