diff --git a/manifest.json b/manifest.json index 7fea7f3..3f2d21a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "float-search", "name": "Floating Search", - "version": "3.1.3", + "version": "3.2.0", "minAppVersion": "0.15.0", "description": "You can use search view in modal now.", "author": "Boninall", @@ -12,4 +12,4 @@ "支付宝": "https://cdn.jsdelivr.net/gh/Quorafind/.github@main/IMAGE/%E6%94%AF%E4%BB%98%E5%AE%9D%E4%BB%98%E6%AC%BE%E7%A0%81.jpg" }, "isDesktopOnly": false -} +} \ No newline at end of file diff --git a/package.json b/package.json index 0dd29c5..50ef199 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "float-search", - "version": "3.1.3", + "version": "3.2.0", "description": "You can use search view in modal now.", "main": "main.js", "scripts": { diff --git a/src/floatSearchIndex.ts b/src/floatSearchIndex.ts index 3e6bc31..510312b 100644 --- a/src/floatSearchIndex.ts +++ b/src/floatSearchIndex.ts @@ -223,6 +223,32 @@ export default class FloatSearchPlugin extends Plugin { } }); + + this.addCommand({ + id: 'search-in-backlink', + name: 'Search In Backlink Of Current File', + checkCallback: (checking: boolean) => { + // Conditions to check + const activeLeaf = this.app.workspace.activeLeaf; + if(!activeLeaf) return; + + const viewType = activeLeaf.view.getViewType(); + if (viewType === "markdown" || viewType === "canvas") { + if (!checking) { + const currentFile = activeLeaf.view.file; + + this.modal = new FloatSearchModal((state)=>{ + this.state = state; + this.applySettingsUpdate(); + },this.app, this, {...this.state, query: " /\\[\\[" + (currentFile.extension === "canvas" ? currentFile.name : currentFile.basename) + "(\\|[^\\]]*)?\\]\\]/", current: true }); + this.modal.open(); + } + + return true; + } + } + }); + this.addCommand({ id: 'search-in-current-file', name: 'Search In Current File', @@ -331,12 +357,14 @@ class FloatSearchModal extends Modal { private searchCtnEl: HTMLElement; private instructionsEl: HTMLElement; private fileEl: HTMLElement; + private viewType: string; - constructor(cb: (state: any)=> void, app: App, plugin: FloatSearchPlugin, state: any) { + constructor(cb: (state: any)=> void, app: App, plugin: FloatSearchPlugin, state: any, viewType: string = "search") { super(app); this.plugin = plugin; this.cb = cb; this.state = state; + this.viewType = viewType; } async onOpen() { @@ -347,7 +375,7 @@ class FloatSearchModal extends Modal { this.initInstructions(this.instructionsEl); this.initCss(contentEl, modalEl, containerEl); - await this.initSearchView(this.searchCtnEl); + await this.initSearchView(this.searchCtnEl, this.viewType); this.initInput(); this.initContent(); } @@ -416,7 +444,7 @@ class FloatSearchModal extends Modal { containerEl.classList.add("float-search-modal-container"); } - async initSearchView(contentEl: HTMLElement) { + async initSearchView(contentEl: HTMLElement, viewType: string) { const [createdLeaf, embeddedView] = spawnLeafView(this.plugin, contentEl); this.searchLeaf = createdLeaf; this.searchEmbeddedView = embeddedView;