#102 - Added url scheme + small refactor for public api
This commit is contained in:
@@ -2,16 +2,18 @@
|
||||
import { debounce } from 'obsidian'
|
||||
import { toggleInputComposition } from 'src/globals'
|
||||
import { createEventDispatcher, tick } from 'svelte'
|
||||
import { cacheManager } from "../cache-manager"
|
||||
import { cacheManager } from '../cache-manager'
|
||||
|
||||
export let initialValue = ''
|
||||
let initialSet = false
|
||||
export let placeholder = ''
|
||||
let value = ''
|
||||
let elInput: HTMLInputElement
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
$: {
|
||||
if (initialValue) {
|
||||
if (initialValue && !initialSet) {
|
||||
initialSet = true
|
||||
value = initialValue
|
||||
selectInput()
|
||||
}
|
||||
@@ -42,9 +44,9 @@
|
||||
on:compositionend="{_ => toggleInputComposition(false)}"
|
||||
on:compositionstart="{_ => toggleInputComposition(true)}"
|
||||
on:input="{debouncedOnInput}"
|
||||
{placeholder}
|
||||
placeholder="{placeholder}"
|
||||
spellcheck="false"
|
||||
type="text"/>
|
||||
type="text" />
|
||||
</div>
|
||||
<slot></slot>
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
@@ -228,7 +228,7 @@
|
||||
</script>
|
||||
|
||||
<InputSearch
|
||||
initialValue="{previousQuery}"
|
||||
initialValue="{searchQuery}"
|
||||
on:input="{e => (searchQuery = e.detail)}"
|
||||
placeholder="Omnisearch - Vault">
|
||||
{#if settings.showCreateButton}
|
||||
|
||||
27
src/main.ts
27
src/main.ts
@@ -6,7 +6,6 @@ import {
|
||||
} from './components/modals'
|
||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
||||
import { eventBus, EventNames, IndexingStep } from './globals'
|
||||
import { registerAPI } from '@vanakat/plugin-api'
|
||||
import api from './tools/api'
|
||||
import { isFilePlaintext, wait } from './tools/utils'
|
||||
import * as NotesIndex from './notes-index'
|
||||
@@ -22,7 +21,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
await OmnisearchCache.clearOldDatabases()
|
||||
await loadSettings(this)
|
||||
|
||||
_registerAPI(this)
|
||||
registerAPI(this)
|
||||
|
||||
if (settings.ribbonIcon) {
|
||||
this.addRibbonButton()
|
||||
@@ -84,7 +83,10 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
showWelcomeNotice(this)
|
||||
}
|
||||
|
||||
onunload(): void {}
|
||||
onunload(): void {
|
||||
// @ts-ignore
|
||||
delete globalThis['omnisearch']
|
||||
}
|
||||
|
||||
addRibbonButton(): void {
|
||||
this.ribbonButton = this.addRibbonIcon('search', 'Omnisearch', _evt => {
|
||||
@@ -161,7 +163,9 @@ async function populateIndex(): Promise<void> {
|
||||
console.log('Omnisearch - Checking index cache diff...')
|
||||
// Check which documents need to be removed/added/updated
|
||||
const diffDocs = await cacheManager.getDiffDocuments(allFiles)
|
||||
console.log(`Omnisearch - Files to add/remove/update: ${diffDocs.toAdd.length}/${diffDocs.toDelete.length}/${diffDocs.toUpdate.length}`)
|
||||
console.log(
|
||||
`Omnisearch - Files to add/remove/update: ${diffDocs.toAdd.length}/${diffDocs.toDelete.length}/${diffDocs.toUpdate.length}`
|
||||
)
|
||||
needToUpdateCache = !!(
|
||||
diffDocs.toAdd.length ||
|
||||
diffDocs.toDelete.length ||
|
||||
@@ -232,10 +236,15 @@ You can now enable "Images Indexing" to use Optical Character Recognition on you
|
||||
plugin.saveData(settings)
|
||||
}
|
||||
|
||||
function _registerAPI(plugin: OmnisearchPlugin): void {
|
||||
registerAPI('omnisearch', api, plugin as any)
|
||||
;(app as any).plugins.plugins.omnisearch.api = api
|
||||
plugin.register(() => {
|
||||
delete (app as any).plugins.plugins.omnisearch.api
|
||||
function registerAPI(plugin: OmnisearchPlugin): void {
|
||||
// Url scheme for obsidian://omnisearch?query=foobar
|
||||
plugin.registerObsidianProtocolHandler('omnisearch', params => {
|
||||
new OmnisearchVaultModal(app, params.query).open()
|
||||
})
|
||||
|
||||
// Public api
|
||||
// @ts-ignore
|
||||
globalThis['omnisearch'] = api
|
||||
// Deprecated
|
||||
;(app as any).plugins.plugins.omnisearch.api = api
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ResultNote, SearchMatch } from '../globals'
|
||||
import type { ResultNote } from '../globals'
|
||||
import { Query } from '../search/query'
|
||||
import { SearchEngine } from '../search/search-engine'
|
||||
|
||||
@@ -7,7 +7,12 @@ type ResultNoteApi = {
|
||||
path: string
|
||||
basename: string
|
||||
foundWords: string[]
|
||||
matches: SearchMatch[]
|
||||
matches: SearchMatchApi[]
|
||||
}
|
||||
|
||||
export type SearchMatchApi = {
|
||||
match: string
|
||||
offset: number
|
||||
}
|
||||
|
||||
function mapResults(results: ResultNote[]): ResultNoteApi[] {
|
||||
|
||||
Reference in New Issue
Block a user