From 08ad35babe9c40c67992003da504ff3adf321cb7 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 7 Mar 2025 21:54:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=E5=9B=BE=E7=89=87=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F,=20?= =?UTF-8?q?=E4=BF=9D=E7=95=99activefile=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main.ts b/src/main.ts index e2924b2..7bd941b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -342,6 +342,12 @@ export default class DiscourseSyncPlugin extends Plugin { } await this.app.vault.modify(activeFile, newContent); + // 更新 activeFile 对象,确保它反映最新状态 + this.activeFile = { + name: activeFile.basename, + content: newContent, + postId: postId + }; } catch (error) { return { message: "Error", @@ -517,23 +523,21 @@ export default class DiscourseSyncPlugin extends Plugin { } private async openCategoryModal() { - // 确保activeFile已设置 - if (!this.activeFile) { - const activeFile = this.app.workspace.getActiveFile(); - if (!activeFile) { - new NotifyUser(this.app, t('NO_ACTIVE_FILE')).open(); - return; - } - - const content = await this.app.vault.read(activeFile); - const fm = this.getFrontMatter(content); - this.activeFile = { - name: activeFile.basename, - content: content, - postId: fm?.discourse_post_id - }; + // 每次都重新获取 activeFile 的最新内容,不使用缓存 + const activeFile = this.app.workspace.getActiveFile(); + if (!activeFile) { + new NotifyUser(this.app, t('NO_ACTIVE_FILE')).open(); + return; } + const content = await this.app.vault.read(activeFile); + const fm = this.getFrontMatter(content); + this.activeFile = { + name: activeFile.basename, + content: content, + postId: fm?.discourse_post_id + }; + const [categories, tags] = await Promise.all([ this.fetchCategories(), this.fetchTags()