diff --git a/src/DocumentHistoryModal.ts b/src/DocumentHistoryModal.ts index 7add563..2e34246 100644 --- a/src/DocumentHistoryModal.ts +++ b/src/DocumentHistoryModal.ts @@ -146,6 +146,17 @@ export class DocumentHistoryModal extends Modal { Logger(`Old content copied to clipboard`, LOG_LEVEL.NOTICE); }); }); + async function focusFile(path: string) { + const targetFile = app.vault + .getFiles() + .find((f) => f.path === path); + if (targetFile) { + const leaf = app.workspace.getLeaf(false); + await leaf.openFile(targetFile); + } else { + Logger("The file cound not view on the editor", LOG_LEVEL.NOTICE) + } + } buttons.createEl("button", { text: "Back to this revision" }, (e) => { e.addClass("mod-cta"); e.addEventListener("click", async () => { @@ -155,9 +166,11 @@ export class DocumentHistoryModal extends Modal { } if (this.currentDoc?.datatype == "plain") { await this.app.vault.adapter.write(pathToWrite, this.currentDoc.data); + await focusFile(pathToWrite); this.close(); } else if (this.currentDoc?.datatype == "newnote") { await this.app.vault.adapter.writeBinary(pathToWrite, base64ToArrayBuffer(this.currentDoc.data)); + await focusFile(pathToWrite); this.close(); } else { diff --git a/src/LocalPouchDB.ts b/src/LocalPouchDB.ts index aa71156..b23ecc9 100644 --- a/src/LocalPouchDB.ts +++ b/src/LocalPouchDB.ts @@ -462,6 +462,7 @@ export class LocalPouchDB { } else { obj = await this.localDatabase.get(id); } + const revDeletion = ("rev" in opt ? opt.rev : "") != ""; if (obj.type && obj.type == "leaf") { //do nothing for leaf; @@ -479,11 +480,15 @@ export class LocalPouchDB { // simple note } if (obj.type == "newnote" || obj.type == "plain") { - obj.deleted = true; - if (this.settings.deleteMetadataOfDeletedFiles) { + if (revDeletion) { obj._deleted = true; + } else { + obj.deleted = true; + obj.mtime = Date.now(); + if (this.settings.deleteMetadataOfDeletedFiles) { + obj._deleted = true; + } } - obj.mtime = Date.now(); const r = await this.localDatabase.put(obj); Logger(`entry removed:${obj._id}-${r.rev}`); if (typeof this.corruptedEntries[obj._id] != "undefined") {