From cf5c38950536cd6662cc7a78a4c0ed4b017aab37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 3 Sep 2025 09:02:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=9D=E7=BB=B4=E5=AF=BC=E5=9B=BE=E5=92=8Cmd?= =?UTF-8?q?=E4=BA=92=E7=9B=B8=E8=BD=AC=E6=8D=A2=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=A2=9E=E5=8A=A0=E5=92=8C=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=8C=B9=E9=85=8D=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/ob/Menus.js | 71 ++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/plugin/ob/Menus.js b/plugin/ob/Menus.js index d2adc21..8e78345 100644 --- a/plugin/ob/Menus.js +++ b/plugin/ob/Menus.js @@ -49,9 +49,8 @@ export default class Menus { .onClick(async () => { await this.app.workspace.openLinkText(file.path, '') const leaf = this.app.workspace.getLeaf(false) - const mdViewType = this.app.viewRegistry.getTypeByExtension( - 'md' - ) + const mdViewType = + this.app.viewRegistry.getTypeByExtension('md') await leaf.setViewState({ type: mdViewType, state: { @@ -98,14 +97,11 @@ export default class Menus { let newPath = file.path.replace('.smm.md', '.md') newPath = await this.plugin._getAvailableFilaName(newPath) await this.app.vault.rename(file, newPath) - const renamedFile = this.app.vault.getFileByPath( - newPath - ) + const renamedFile = this.app.vault.getFileByPath(newPath) if (renamedFile) { // 关闭当前标签页 - const markdownLeafs = this.app.workspace.getLeavesOfType( - SMM_VIEW_TYPE - ) + const markdownLeafs = + this.app.workspace.getLeavesOfType(SMM_VIEW_TYPE) for (const leaf of markdownLeafs) { if (leaf.view.file.path === renamedFile.path) { leaf.view.isActive = false @@ -116,15 +112,20 @@ export default class Menus { // 修改文件内容 await this.app.vault.modify(renamedFile, mdStr) // 重新打开 - const ref = this.app.metadataCache.on('changed', () => { - this.app.metadataCache.offref(ref) - this.app.workspace.openLinkText( - renamedFile.path, - '', - true - ) - new Notice(this._t('tip.changeSuccess')) - }) + const ref = this.app.metadataCache.on( + 'changed', + changedFile => { + if (changedFile.path === renamedFile.path) { + this.app.metadataCache.offref(ref) + this.app.workspace.openLinkText( + renamedFile.path, + '', + true + ) + new Notice(this._t('tip.changeSuccess')) + } + } + ) } }) ) @@ -140,7 +141,7 @@ export default class Menus { this.plugin.register( around(MarkdownView.prototype, { onPaneMenu(next) { - return function(menu, source) { + return function (menu, source) { const res = next.apply(this, [menu, source]) if (self.plugin._isSmmFile(this.file)) { if (source === 'more-options') { @@ -211,9 +212,7 @@ export default class Menus { 2 ) await this.app.vault.rename(this.file, newPath) - const renamedFile = this.app.vault.getFileByPath( - newPath - ) + const renamedFile = this.app.vault.getFileByPath(newPath) const str = assembleMarkdownText({ metadata: { path: `${newPath || ''}`, @@ -228,9 +227,8 @@ export default class Menus { }) if (renamedFile) { // 关闭当前标签页 - const markdownLeafs = this.app.workspace.getLeavesOfType( - 'markdown' - ) + const markdownLeafs = + this.app.workspace.getLeavesOfType('markdown') for (const leaf of markdownLeafs) { if (leaf.view.file.path === renamedFile.path) { leaf.detach() @@ -240,15 +238,20 @@ export default class Menus { // 修改文件内容 await this.app.vault.modify(renamedFile, str) // 重新打开 - const ref = this.app.metadataCache.on('changed', () => { - this.app.metadataCache.offref(ref) - this.app.workspace.openLinkText( - renamedFile.path, - '', - true - ) - new Notice(self._t('tip.changeSuccess')) - }) + const ref = this.app.metadataCache.on( + 'changed', + changedFile => { + if (changedFile.path === renamedFile.path) { + this.app.metadataCache.offref(ref) + this.app.workspace.openLinkText( + renamedFile.path, + '', + true + ) + new Notice(self._t('tip.changeSuccess')) + } + } + ) } }) )