From a45ac9f008e723a3ce20f51523c1fc47acdd1a0b Mon Sep 17 00:00:00 2001 From: lazyloong <2950449004@qq.com> Date: Sat, 19 Oct 2024 15:07:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=AF=B9=E6=96=87=E4=BB=B6=E6=A0=91=E4=B8=AD?= =?UTF-8?q?=E8=A2=AB=E9=80=89=E6=8B=A9=E7=9A=84=E6=96=87=E4=BB=B6=E6=97=A0?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- src/main.ts | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/manifest.json b/manifest.json index d47ed65..d8f5bc1 100644 --- a/manifest.json +++ b/manifest.json @@ -5,5 +5,5 @@ "author": "lazyloong", "minAppVersion": "1.0.0", - "version": "2.27.4" + "version": "2.27.5" } diff --git a/src/main.ts b/src/main.ts index c8db3ca..1081c0b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -130,8 +130,7 @@ export default class ThePlugin extends Plugin { let files = this.fileExplorerHotkey.getFiles(); let file = this.app.workspace.getActiveFile(); if (checking) return Boolean(file) || files.length > 0; - if (this.fileExplorerHotkey.working && files.length > 0) - this.folderModal.openWithFiles(files); + if (files.length > 0) this.folderModal.openWithFiles(files); else if (file) this.folderModal.open(); }, }); @@ -227,25 +226,31 @@ class FileExplorerHotkey { app: App; leaf: WorkspaceLeaf; view: View; - working = false; constructor(app: App, plugin: ThePlugin) { this.plugin = plugin; this.app = app; - let leafs = this.app.workspace.getLeavesOfType("file-explorer"); - if (leafs.length == 0) return; - this.leaf = leafs[0]; - this.working = true; - this.view = this.leaf.view; + this.getView(); } getFiles(): TFile[] { - // @ts-ignore - if (this.view === undefined || this.view.tree === undefined) { - // core plugin `Files` is disabled - return []; + if (!this.viewIsWorkable()) { + this.getView(); + if (!this.viewIsWorkable()) return []; } // @ts-ignore return Array.from(this.view.tree.selectedDoms).map((p: { file: TFile }) => p.file); } + getView(): View | undefined { + let leaf = this.app.workspace.getLeavesOfType("file-explorer"); + if (leaf.length != 0) { + this.leaf = leaf[0]; + this.view = this.leaf.view; + } + return this.view; + } + viewIsWorkable(): boolean { + // @ts-ignore + return Boolean(this.view?.tree?.selectedDoms); + } } class IndexManager extends Array> {