WIP in-file search
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/svelte": "^3.0.0",
|
"@tsconfig/svelte": "^3.0.0",
|
||||||
"@types/lodash-es": "^4.17.6",
|
|
||||||
"@types/node": "^16.11.6",
|
"@types/node": "^16.11.6",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
||||||
"@typescript-eslint/parser": "^5.18.0",
|
"@typescript-eslint/parser": "^5.18.0",
|
||||||
@@ -36,7 +35,6 @@
|
|||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash-es": "^4.17.21",
|
|
||||||
"minisearch": "^5.0.0-beta1"
|
"minisearch": "^5.0.0-beta1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@@ -2,7 +2,6 @@ lockfileVersion: 5.3
|
|||||||
|
|
||||||
specifiers:
|
specifiers:
|
||||||
'@tsconfig/svelte': ^3.0.0
|
'@tsconfig/svelte': ^3.0.0
|
||||||
'@types/lodash-es': ^4.17.6
|
|
||||||
'@types/node': ^16.11.6
|
'@types/node': ^16.11.6
|
||||||
'@typescript-eslint/eslint-plugin': ^5.18.0
|
'@typescript-eslint/eslint-plugin': ^5.18.0
|
||||||
'@typescript-eslint/parser': ^5.18.0
|
'@typescript-eslint/parser': ^5.18.0
|
||||||
@@ -16,7 +15,6 @@ specifiers:
|
|||||||
eslint-plugin-node: 11.1.0
|
eslint-plugin-node: 11.1.0
|
||||||
eslint-plugin-promise: 5.0.0
|
eslint-plugin-promise: 5.0.0
|
||||||
eslint-plugin-svelte3: ^3.4.1
|
eslint-plugin-svelte3: ^3.4.1
|
||||||
lodash-es: ^4.17.21
|
|
||||||
minisearch: ^5.0.0-beta1
|
minisearch: ^5.0.0-beta1
|
||||||
obsidian: latest
|
obsidian: latest
|
||||||
prettier: ^2.6.2
|
prettier: ^2.6.2
|
||||||
@@ -27,12 +25,10 @@ specifiers:
|
|||||||
typescript: ^4.6.3
|
typescript: ^4.6.3
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
lodash-es: 4.17.21
|
|
||||||
minisearch: 5.0.0-beta1
|
minisearch: 5.0.0-beta1
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@tsconfig/svelte': 3.0.0
|
'@tsconfig/svelte': 3.0.0
|
||||||
'@types/lodash-es': 4.17.6
|
|
||||||
'@types/node': 16.11.26
|
'@types/node': 16.11.26
|
||||||
'@typescript-eslint/eslint-plugin': 5.18.0_2e93aa916703472007e9b5dfec98785b
|
'@typescript-eslint/eslint-plugin': 5.18.0_2e93aa916703472007e9b5dfec98785b
|
||||||
'@typescript-eslint/parser': 5.18.0_eslint@7.12.1+typescript@4.6.3
|
'@typescript-eslint/parser': 5.18.0_eslint@7.12.1+typescript@4.6.3
|
||||||
@@ -168,16 +164,6 @@ packages:
|
|||||||
resolution: {integrity: sha1-7ihweulOEdK4J7y+UnC86n8+ce4=}
|
resolution: {integrity: sha1-7ihweulOEdK4J7y+UnC86n8+ce4=}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@types/lodash-es/4.17.6:
|
|
||||||
resolution: {integrity: sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==}
|
|
||||||
dependencies:
|
|
||||||
'@types/lodash': 4.14.181
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@types/lodash/4.14.181:
|
|
||||||
resolution: {integrity: sha512-n3tyKthHJbkiWhDZs3DkhkCzt2MexYHXlX0td5iMplyfwketaOeKboEVBqzceH7juqvEg3q5oUoBFxSLu7zFag==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@types/node/16.11.26:
|
/@types/node/16.11.26:
|
||||||
resolution: {integrity: sha512-GZ7bu5A6+4DtG7q9GsoHXy3ALcgeIHP4NnL0Vv2wu0uUB/yQex26v0tf6/na1mm0+bS9Uw+0DFex7aaKr2qawQ==}
|
resolution: {integrity: sha512-GZ7bu5A6+4DtG7q9GsoHXy3ALcgeIHP4NnL0Vv2wu0uUB/yQex26v0tf6/na1mm0+bS9Uw+0DFex7aaKr2qawQ==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -1561,10 +1547,6 @@ packages:
|
|||||||
path-exists: 3.0.0
|
path-exists: 3.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/lodash-es/4.17.21:
|
|
||||||
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/lodash.merge/4.6.2:
|
/lodash.merge/4.6.2:
|
||||||
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ onMount(async () => {
|
|||||||
await tick()
|
await tick()
|
||||||
input.focus()
|
input.focus()
|
||||||
input.select()
|
input.select()
|
||||||
|
input.value = $searchQuery
|
||||||
})
|
})
|
||||||
|
|
||||||
const debouncedOnInput = debounce(() => $searchQuery = inputValue, 100)
|
const debouncedOnInput = debounce(() => $searchQuery = inputValue, 100)
|
||||||
@@ -41,6 +42,9 @@ function moveNoteSelection(ev: KeyboardEvent): void {
|
|||||||
} else if (ev.shiftKey) {
|
} else if (ev.shiftKey) {
|
||||||
// Create a new note
|
// Create a new note
|
||||||
dispatch("shift-enter", $selectedNote)
|
dispatch("shift-enter", $selectedNote)
|
||||||
|
} else if (ev.altKey) {
|
||||||
|
// Create a new note
|
||||||
|
dispatch("alt-enter", $selectedNote)
|
||||||
} else {
|
} else {
|
||||||
// Open in current pane
|
// Open in current pane
|
||||||
dispatch("enter", $selectedNote)
|
dispatch("enter", $selectedNote)
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tick } from "svelte"
|
import { onMount, tick } from "svelte"
|
||||||
import CmpInput from "./CmpInput.svelte"
|
import CmpInput from "./CmpInput.svelte"
|
||||||
|
import CmpNoteInternalResult from "./CmpNoteInternalResult.svelte"
|
||||||
import CmpNoteResult from "./CmpNoteResult.svelte"
|
import CmpNoteResult from "./CmpNoteResult.svelte"
|
||||||
import type { ResultNote } from "./globals"
|
import type { ResultNote } from "./globals"
|
||||||
import { openNote } from "./notes"
|
import { openNote } from "./notes"
|
||||||
import { getSuggestions } from "./search"
|
import { getSuggestions } from "./search"
|
||||||
import {
|
import {
|
||||||
|
inFileSearch,
|
||||||
modal,
|
modal,
|
||||||
plugin,
|
plugin,
|
||||||
resultNotes,
|
resultNotes,
|
||||||
@@ -13,8 +15,18 @@ import {
|
|||||||
selectedNote,
|
selectedNote,
|
||||||
} from "./stores"
|
} from "./stores"
|
||||||
|
|
||||||
|
$: firstResult = $resultNotes[0]
|
||||||
|
|
||||||
searchQuery.subscribe(async (q) => {
|
searchQuery.subscribe(async (q) => {
|
||||||
const results = getSuggestions(q)
|
// If we're in "single file" mode, the search results array
|
||||||
|
// will contain a single result, related to this file
|
||||||
|
const results = $inFileSearch
|
||||||
|
? getSuggestions(q, { singleFile: $inFileSearch })
|
||||||
|
: getSuggestions(q)
|
||||||
|
|
||||||
|
console.log(results)
|
||||||
|
|
||||||
|
// Search on the whole vault
|
||||||
resultNotes.set(results)
|
resultNotes.set(results)
|
||||||
const firstResult = results[0]
|
const firstResult = results[0]
|
||||||
if (firstResult) {
|
if (firstResult) {
|
||||||
@@ -57,18 +69,32 @@ function onInputShiftEnter(event: CustomEvent<ResultNote>): void {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class="modal-title">Omnisearch</div>
|
||||||
<CmpInput
|
<CmpInput
|
||||||
on:enter={onInputEnter}
|
on:enter={onInputEnter}
|
||||||
on:shift-enter={onInputShiftEnter}
|
on:shift-enter={onInputShiftEnter}
|
||||||
on:ctrl-enter={onInputCtrlEnter}
|
on:ctrl-enter={onInputCtrlEnter}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="prompt-results">
|
<div class="modal-content">
|
||||||
|
<div class="prompt-results">
|
||||||
|
{#if $inFileSearch}
|
||||||
|
<!-- In-file results -->
|
||||||
|
{#if firstResult}
|
||||||
|
{#each firstResult.matches as match}
|
||||||
|
<CmpNoteInternalResult {match} />
|
||||||
|
{/each}
|
||||||
|
{:else}
|
||||||
|
We found 0 result for your search here.
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<!-- Multi-files results -->
|
||||||
{#each $resultNotes as result}
|
{#each $resultNotes as result}
|
||||||
<CmpNoteResult selected={result === $selectedNote} note={result} />
|
<CmpNoteResult selected={result === $selectedNote} note={result} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
{/if}
|
||||||
<div class="prompt-instructions">
|
</div>
|
||||||
|
<div class="prompt-instructions">
|
||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
|
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -76,15 +102,15 @@ function onInputShiftEnter(event: CustomEvent<ResultNote>): void {
|
|||||||
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">ctrl ↵</span><span
|
<span class="prompt-instruction-command">ctrl ↵</span>
|
||||||
>to open in a new pane</span
|
<span>to open in a new pane</span>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">shift ↵</span><span>to create</span
|
<span class="prompt-instruction-command">shift ↵</span>
|
||||||
>
|
<span>to create</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">esc</span><span>to dismiss</span>
|
<span class="prompt-instruction-command">esc</span><span>to dismiss</span>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
11
src/CmpNoteInternalResult.svelte
Normal file
11
src/CmpNoteInternalResult.svelte
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { SearchMatch } from "./globals"
|
||||||
|
|
||||||
|
export let match: SearchMatch
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="suggestion-item omnisearch-result">
|
||||||
|
<div class="omnisearch-result__body">
|
||||||
|
{JSON.stringify(match)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
24
src/main.ts
24
src/main.ts
@@ -1,9 +1,9 @@
|
|||||||
import { Plugin, TFile } from 'obsidian'
|
import { MarkdownView, Plugin, TFile } from 'obsidian'
|
||||||
import { OmnisearchModal } from './modal'
|
import { OmnisearchModal } from './modal'
|
||||||
import { plugin } from './stores'
|
import { plugin } from './stores'
|
||||||
import {
|
import {
|
||||||
addToIndex,
|
addToIndex,
|
||||||
instantiateMinisearch,
|
initGlobalSearchIndex,
|
||||||
removeFromIndex,
|
removeFromIndex,
|
||||||
removeFromIndexByPath,
|
removeFromIndexByPath,
|
||||||
} from './search'
|
} from './search'
|
||||||
@@ -12,18 +12,34 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
async onload(): Promise<void> {
|
async onload(): Promise<void> {
|
||||||
plugin.set(this)
|
plugin.set(this)
|
||||||
|
|
||||||
await instantiateMinisearch()
|
await initGlobalSearchIndex()
|
||||||
|
|
||||||
// Commands to display Omnisearch modal
|
// Commands to display Omnisearch modal
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: 'show-modal',
|
id: 'show-modal',
|
||||||
name: 'Open Omnisearch',
|
name: 'Vault search',
|
||||||
// hotkeys: [{ modifiers: ['Mod'], key: 'o' }],
|
// hotkeys: [{ modifiers: ['Mod'], key: 'o' }],
|
||||||
callback: () => {
|
callback: () => {
|
||||||
new OmnisearchModal(this).open()
|
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
|
// Listeners to keep the search index up-to-date
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.vault.on('create', file => {
|
this.app.vault.on('create', file => {
|
||||||
|
|||||||
14
src/modal.ts
14
src/modal.ts
@@ -1,13 +1,19 @@
|
|||||||
import { Modal } from 'obsidian'
|
import { Modal, TFile } from 'obsidian'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
import CmpModal from './CmpModal.svelte'
|
import CmpModal from './CmpModal.svelte'
|
||||||
import { modal } from './stores'
|
import { inFileSearch, modal } from './stores'
|
||||||
|
|
||||||
export class OmnisearchModal extends Modal {
|
export class OmnisearchModal extends Modal {
|
||||||
constructor(plugin: OmnisearchPlugin) {
|
constructor(plugin: OmnisearchPlugin, file?: TFile) {
|
||||||
super(plugin.app)
|
super(plugin.app)
|
||||||
|
// Remove all the default modal's children (except the close button)
|
||||||
|
// so that we can more easily customize it
|
||||||
|
const closeEl = this.containerEl.find('.modal-close-button')
|
||||||
|
this.modalEl.replaceChildren()
|
||||||
|
this.modalEl.append(closeEl)
|
||||||
this.modalEl.addClass('omnisearch-modal', 'prompt')
|
this.modalEl.addClass('omnisearch-modal', 'prompt')
|
||||||
this.modalEl.replaceChildren() // Remove all the default Modal's children
|
|
||||||
|
inFileSearch.set(file ?? null)
|
||||||
|
|
||||||
modal.set(this)
|
modal.set(this)
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
import { Notice, TFile, type TAbstractFile } from 'obsidian'
|
import { Notice, TFile, type TAbstractFile } from 'obsidian'
|
||||||
import MiniSearch from 'minisearch'
|
import MiniSearch, { type SearchResult } from 'minisearch'
|
||||||
import type { IndexedNote, ResultNote, SearchMatch } from './globals'
|
import type { IndexedNote, ResultNote, SearchMatch } from './globals'
|
||||||
import { indexedNotes, plugin } from './stores'
|
import { indexedNotes, plugin } from './stores'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
import {
|
import { extractHeadingsFromCache, stringsToRegex, wait } from './utils'
|
||||||
escapeRegex,
|
|
||||||
extractHeadingsFromCache,
|
|
||||||
getAllIndices,
|
|
||||||
stringsToRegex,
|
|
||||||
wait,
|
|
||||||
} from './utils'
|
|
||||||
|
|
||||||
let minisearch: MiniSearch<IndexedNote>
|
let minisearchInstance: MiniSearch<IndexedNote>
|
||||||
|
|
||||||
export async function instantiateMinisearch(): Promise<void> {
|
export async function initGlobalSearchIndex(): Promise<void> {
|
||||||
indexedNotes.set({})
|
indexedNotes.set({})
|
||||||
minisearch = new MiniSearch({
|
minisearchInstance = new MiniSearch({
|
||||||
idField: 'path',
|
idField: 'path',
|
||||||
fields: ['basename', 'content', 'headings1', 'headings2', 'headings3'],
|
fields: ['basename', 'content', 'headings1', 'headings2', 'headings3'],
|
||||||
})
|
})
|
||||||
@@ -54,9 +48,8 @@ export function getMatches(text: string, reg: RegExp): SearchMatch[] {
|
|||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSuggestions(query: string): ResultNote[] {
|
function search(query: string): SearchResult[] {
|
||||||
const results = minisearch
|
return minisearchInstance.search(query, {
|
||||||
.search(query, {
|
|
||||||
prefix: true,
|
prefix: true,
|
||||||
fuzzy: term => (term.length > 4 ? 0.2 : false),
|
fuzzy: term => (term.length > 4 ? 0.2 : false),
|
||||||
combineWith: 'AND',
|
combineWith: 'AND',
|
||||||
@@ -67,10 +60,22 @@ export function getSuggestions(query: string): ResultNote[] {
|
|||||||
headings3: 1.1,
|
headings3: 1.1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.sort((a, b) => b.score - a.score)
|
}
|
||||||
.slice(0, 50)
|
|
||||||
// console.log(`Omnisearch - Results for "${query}"`)
|
export function getSuggestions(
|
||||||
// console.log(results)
|
query: string,
|
||||||
|
options?: Partial<{ singleFile: TFile }>,
|
||||||
|
): ResultNote[] {
|
||||||
|
let results = search(query)
|
||||||
|
if (options?.singleFile) {
|
||||||
|
const file = options.singleFile
|
||||||
|
const result = results.find(r => r.id === file.path)
|
||||||
|
if (result) results = [result]
|
||||||
|
else results = []
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
results = results.sort((a, b) => b.score - a.score).slice(0, 50)
|
||||||
|
}
|
||||||
|
|
||||||
const suggestions = results.map(result => {
|
const suggestions = results.map(result => {
|
||||||
const note = indexedNotes.get(result.id)
|
const note = indexedNotes.get(result.id)
|
||||||
@@ -80,17 +85,11 @@ export function getSuggestions(query: string): ResultNote[] {
|
|||||||
const words = Object.keys(result.match)
|
const words = Object.keys(result.match)
|
||||||
const matches = getMatches(note.content, stringsToRegex(words))
|
const matches = getMatches(note.content, stringsToRegex(words))
|
||||||
const resultNote: ResultNote = {
|
const resultNote: ResultNote = {
|
||||||
// searchResult: result,
|
|
||||||
foundWords: words,
|
foundWords: words,
|
||||||
occurence: 0,
|
occurence: 0,
|
||||||
matches,
|
matches,
|
||||||
...note,
|
...note,
|
||||||
}
|
}
|
||||||
// if (note.basename === 'Search') {
|
|
||||||
// console.log('=======')
|
|
||||||
// console.log(result)
|
|
||||||
// console.log(resultNote)
|
|
||||||
// }
|
|
||||||
return resultNote
|
return resultNote
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ export async function addToIndex(file: TAbstractFile): Promise<void> {
|
|||||||
? extractHeadingsFromCache(fileCache, 3).join(' ')
|
? extractHeadingsFromCache(fileCache, 3).join(' ')
|
||||||
: '',
|
: '',
|
||||||
}
|
}
|
||||||
minisearch.add(note)
|
minisearchInstance.add(note)
|
||||||
indexedNotes.add(note)
|
indexedNotes.add(note)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@@ -146,7 +145,7 @@ export function removeFromIndex(file: TAbstractFile): void {
|
|||||||
export function removeFromIndexByPath(path: string): void {
|
export function removeFromIndexByPath(path: string): void {
|
||||||
const note = indexedNotes.get(path)
|
const note = indexedNotes.get(path)
|
||||||
if (note) {
|
if (note) {
|
||||||
minisearch.remove(note)
|
minisearchInstance.remove(note)
|
||||||
indexedNotes.remove(path)
|
indexedNotes.remove(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { TFile } from 'obsidian'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import type { IndexedNote, ResultNote } from './globals'
|
import type { IndexedNote, ResultNote } from './globals'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
@@ -52,9 +53,37 @@ function createSelectedNote() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this field is set, the search will be limited to the given file
|
||||||
|
*/
|
||||||
|
export const inFileSearch = writable<TFile | null>(null)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current search query
|
||||||
|
*/
|
||||||
export const searchQuery = writable<string>('')
|
export const searchQuery = writable<string>('')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The search results list, according to the current search query
|
||||||
|
*/
|
||||||
export const resultNotes = writable<ResultNote[]>([])
|
export const resultNotes = writable<ResultNote[]>([])
|
||||||
export const plugin = writable<OmnisearchPlugin>()
|
|
||||||
export const modal = writable<OmnisearchModal>()
|
/**
|
||||||
|
* The currently selected/hovered note in the results list
|
||||||
|
*/
|
||||||
export const selectedNote = createSelectedNote()
|
export const selectedNote = createSelectedNote()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the plugin instance
|
||||||
|
*/
|
||||||
|
export const plugin = writable<OmnisearchPlugin>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the modal instance
|
||||||
|
*/
|
||||||
|
export const modal = writable<OmnisearchModal>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entire list of indexed notes, constantly kept up-to-date.
|
||||||
|
*/
|
||||||
export const indexedNotes = createIndexedNotes()
|
export const indexedNotes = createIndexedNotes()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
regexYaml,
|
regexYaml,
|
||||||
} from './globals'
|
} from './globals'
|
||||||
import type { SearchMatch } from './globals'
|
import type { SearchMatch } from './globals'
|
||||||
import { uniqBy } from 'lodash-es'
|
|
||||||
|
|
||||||
export function highlighter(str: string): string {
|
export function highlighter(str: string): string {
|
||||||
return '<span class="search-result-file-matched-text">' + str + '</span>'
|
return '<span class="search-result-file-matched-text">' + str + '</span>'
|
||||||
|
|||||||
Reference in New Issue
Block a user