From bbeba1c141993cc6fac7e9f64d719cb06015ebb8 Mon Sep 17 00:00:00 2001 From: lazyloong <2950449004@qq.com> Date: Mon, 8 Jan 2024 12:48:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=AB=E6=8D=B7=E9=94=AE=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=A7=BB=E5=8A=A8=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=A2=AB=E9=80=89=E6=8B=A9=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + manifest.json | 2 +- src/fuzzyFolderModal.ts | 4 +++ src/main.ts | 58 +++++++++++++++++++++++++++++++++++------ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fb66625..f5f0a26 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Obsidian -> 选项 -> 快捷键 -> 搜索 `Fuzzy` -> 给 `Fuzzy Chinese Pinyin: ### 文件移动 命令 `Fuzzy Chinese Pinyin: Move File`,效果类似命令 `将文件移动到其他文件夹`。 +在文件列表中选择文件后,右键可一起移动,若设置了快捷键也可以快捷键打开,优先级大于当前页面文件。 ### 命令搜索 diff --git a/manifest.json b/manifest.json index be6bec2..614a442 100644 --- a/manifest.json +++ b/manifest.json @@ -5,5 +5,5 @@ "author": "lazyloong", "minAppVersion": "1.0.0", - "version": "2.12.0" + "version": "2.13.0" } diff --git a/src/fuzzyFolderModal.ts b/src/fuzzyFolderModal.ts index 538d6b5..6dcaf25 100644 --- a/src/fuzzyFolderModal.ts +++ b/src/fuzzyFolderModal.ts @@ -76,6 +76,10 @@ export default class FuzzyFolderModal extends FuzzyModal { else app.vault.rename(this.toMoveFiles, matchData.item.name + "/" + this.toMoveFiles.name); this.toMoveFiles = null; } + openWithFiles(files: TAbstractFile | TFile[]) { + this.toMoveFiles = files; + this.open(); + } } class PinyinIndex extends PI { diff --git a/src/main.ts b/src/main.ts index 8862a2e..f57bdfd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,16 @@ -import { Plugin, EditorSuggest, WorkspaceLeaf, Menu, TFile, TAbstractFile } from "obsidian"; +import { + Plugin, + EditorSuggest, + WorkspaceLeaf, + Menu, + TFile, + TAbstractFile, + Scope, + App, + KeymapEventHandler, + View, + Hotkey, +} from "obsidian"; import { fullPinyin2doublePinyin, Item, PinyinIndex, runOnLayoutReady } from "./utils"; import FuzzyModal from "./fuzzyModal"; import FuzzyFileModal from "./fuzzyFileModal"; @@ -100,6 +112,7 @@ export default class FuzzyChinesePinyinPlugin extends Plugin { tagEditorSuggest: TagEditorSuggest; indexManager: IndexManager; editorSuggests: EditorSuggest[]; + fileExplorerHotkey: FileExplorerHotkey; async onload() { await this.loadSettings(); @@ -138,6 +151,7 @@ export default class FuzzyChinesePinyinPlugin extends Plugin { } else { this.indexManager.load(); } + this.registerFileExplorer(); }); this.addCommand({ id: "open-search", @@ -157,8 +171,14 @@ export default class FuzzyChinesePinyinPlugin extends Plugin { id: "move-file", name: "Move File", checkCallback: (checking: boolean) => { - let file = app.workspace.getActiveFile(); - if (file) { + let files = this.fileExplorerHotkey.getFiles(); + let file = this.app.workspace.getActiveFile(); + if (this.fileExplorerHotkey.working && files.length > 0) { + if (!checking) { + this.folderModal.openWithFiles(files); + } + return true; + } else if (file) { if (!checking) { this.folderModal.open(); } @@ -242,8 +262,7 @@ export default class FuzzyChinesePinyinPlugin extends Plugin { item.setIcon("folder-tree") .setTitle("FuzzyPinyin: 移动" + title) .onClick(() => { - this.folderModal.toMoveFiles = file; - this.folderModal.open(); + this.folderModal.openWithFiles(file); }); }); }) @@ -252,15 +271,38 @@ export default class FuzzyChinesePinyinPlugin extends Plugin { this.app.workspace.on("files-menu", (menu: Menu, files: TFile[]) => { menu.addItem((item) => { item.setIcon("folder-tree") - .setTitle(`FuzzyPinyin: 移动${files.length}个文件`) + .setTitle(`FuzzyPinyin: 移动 ${files.length} 个文件`) .onClick(() => { - this.folderModal.toMoveFiles = files; - this.folderModal.open(); + this.folderModal.openWithFiles(files); }); }); }) ); } + registerFileExplorer() { + this.fileExplorerHotkey = new FileExplorerHotkey(this.app, this); + } +} + +class FileExplorerHotkey { + plugin: FuzzyChinesePinyinPlugin; + app: App; + leaf: WorkspaceLeaf; + view: View; + working = false; + constructor(app: App, plugin: FuzzyChinesePinyinPlugin) { + this.plugin = plugin; + this.app = app; + this.app.workspace.iterateAllLeaves((leaf) => { + if (leaf.view?.tree?.id == "file-explorer") this.leaf = leaf; + }); + if (!this.leaf) return; + this.working = true; + this.view = this.leaf.view; + } + getFiles(): TFile[] { + return Array.from(this.view.tree.selectedDoms).map((p) => p.file); + } } class IndexManager extends Array> {