WIP in-file search

This commit is contained in:
Simon Cambier
2022-04-17 22:03:06 +02:00
parent 34c771cc31
commit cfa24b9617
10 changed files with 164 additions and 94 deletions

View File

@@ -1,9 +1,9 @@
import { Plugin, TFile } from 'obsidian'
import { MarkdownView, Plugin, TFile } from 'obsidian'
import { OmnisearchModal } from './modal'
import { plugin } from './stores'
import {
addToIndex,
instantiateMinisearch,
initGlobalSearchIndex,
removeFromIndex,
removeFromIndexByPath,
} from './search'
@@ -12,18 +12,34 @@ export default class OmnisearchPlugin extends Plugin {
async onload(): Promise<void> {
plugin.set(this)
await instantiateMinisearch()
await initGlobalSearchIndex()
// Commands to display Omnisearch modal
this.addCommand({
id: 'show-modal',
name: 'Open Omnisearch',
name: 'Vault search',
// hotkeys: [{ modifiers: ['Mod'], key: 'o' }],
callback: () => {
new OmnisearchModal(this).open()
},
})
this.addCommand({
id: 'show-modal-infile',
name: 'In-file search',
// hotkeys: [{ modifiers: ['Mod'], key: 'o' }],
checkCallback: (checking: boolean) => {
const view = this.app.workspace.getActiveViewOfType(MarkdownView)
if (view) {
if (!checking) {
new OmnisearchModal(this, view.file).open()
}
return true
}
return false
},
})
// Listeners to keep the search index up-to-date
this.registerEvent(
this.app.vault.on('create', file => {