mirror of
https://github.com/quorafind/Obsidian-Float-Search.git
synced 2026-07-22 07:30:25 +00:00
Merge pull request #10 from Quorafind/feat/support-searching-in-backlink
Feat/support searching in backlink
This commit is contained in:
commit
ae5ff76e33
3 changed files with 34 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue