diff --git a/src/components/ModalInFile.svelte b/src/components/ModalInFile.svelte index 3cff9b9..0397ba5 100644 --- a/src/components/ModalInFile.svelte +++ b/src/components/ModalInFile.svelte @@ -153,7 +153,7 @@ {note} index={i} selected={i === selectedIndex} - on:mousemove={e => (selectedIndex = i)} + on:mousemove={_e => (selectedIndex = i)} on:click={openSelection} /> {/each} {:else} diff --git a/src/event-bus.ts b/src/event-bus.ts index b4af82c..656e74a 100644 --- a/src/event-bus.ts +++ b/src/event-bus.ts @@ -55,7 +55,7 @@ export class EventBus { public emit(event: string, ...args: any[]): void { const entries = [...this.handlers.entries()].filter( - ([k, h]) => !this.disabled.includes(k.split('@')[0]) + ([k, _]) => !this.disabled.includes(k.split('@')[0]) ) for (const [key, handler] of entries) { if (key.endsWith(`@${event}`)) { diff --git a/src/globals.ts b/src/globals.ts index c749668..4074f44 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -1,7 +1,5 @@ import { EventBus } from './event-bus' -// Matches a wikiling that begins a string -export const regexWikilink = /^!?\[\[(?.+?)(\|(?.+?))?\]\]/ export const regexLineSplit = /\r?\n|\r|((\.|\?|!)( |\r?\n|\r))/g export const regexYaml = /^---\s*\n(.*?)\n?^---\s?/ms export const regexStripQuotes = /^"|"$|^'|'$/g @@ -18,12 +16,6 @@ export const searchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/se export const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json` export const historyFilePath = `${app.vault.configDir}/plugins/omnisearch/historyCache.json` -export type SearchNote = { - path: string - basename: string - content: string -} - export type IndexedNote = { path: string basename: string diff --git a/src/main.ts b/src/main.ts index 54846b0..73d35c1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -101,7 +101,7 @@ export default class OmnisearchPlugin extends Plugin { onunload(): void {} addRibbonButton(): void { - this.addRibbonIcon('search', 'Omnisearch', evt => { + this.addRibbonIcon('search', 'Omnisearch', _evt => { new OmnisearchVaultModal(app).open() }) } diff --git a/src/notes.ts b/src/notes.ts index d0c4937..f03e514 100644 --- a/src/notes.ts +++ b/src/notes.ts @@ -43,15 +43,19 @@ export async function loadNotesCache(): Promise { notesCache = {} } } + export function getNoteFromCache(key: string): IndexedNote | undefined { return notesCache[key] } + export function getNonExistingNotesFromCache(): IndexedNote[] { return Object.values(notesCache).filter(note => note.doesNotExist) } + export function addNoteToCache(filename: string, note: IndexedNote): void { notesCache[filename] = note } + export function removeNoteFromCache(key: string): void { delete notesCache[key] } @@ -74,7 +78,7 @@ export async function openNote( leaf.getViewState().state?.file === item.path && leaf.getViewState()?.pinned ) { - app.workspace.setActiveLeaf(leaf, false, true) + app.workspace.setActiveLeaf(leaf, { focus: true }) alreadyOpenAndPinned = true } } @@ -101,7 +105,7 @@ export async function openNote( export async function createNote(name: string, newLeaf = false): Promise { try { - let pathPrefix = '' + let pathPrefix: string switch (app.vault.getConfig('newFileLocation')) { case 'current': pathPrefix = (app.workspace.getActiveFile()?.parent.path ?? '') + '/' @@ -113,7 +117,7 @@ export async function createNote(name: string, newLeaf = false): Promise { pathPrefix = '' break } - app.workspace.openLinkText(`${pathPrefix}${name}.md`, '', newLeaf) + await app.workspace.openLinkText(`${pathPrefix}${name}.md`, '', newLeaf) } catch (e) { ;(e as any).message = 'OmniSearch - Could not create note: ' + (e as any).message diff --git a/src/search.ts b/src/search.ts index c5dc0b7..f69f80a 100644 --- a/src/search.ts +++ b/src/search.ts @@ -80,7 +80,9 @@ export async function initGlobalSearchIndex(): Promise { console.log('Omnisearch - MiniSearch index loaded from the file') await loadNotesCache() } catch (e) { - console.trace('Omnisearch - Could not load MiniSearch index from the file') + console.trace( + 'Omnisearch - Could not load MiniSearch index from the file' + ) console.error(e) } } @@ -138,12 +140,12 @@ export async function initGlobalSearchIndex(): Promise { /** * Searches the index for the given query, * and returns an array of raw results - * @param text + * @param query * @returns */ async function search(query: Query): Promise { if (!query.segmentsToStr()) return [] - + let results = minisearchInstance.search(query.segmentsToStr(), { prefix: true, fuzzy: term => (term.length > 4 ? 0.2 : false), @@ -253,7 +255,7 @@ export async function getSuggestions( } // Map the raw results to get usable suggestions - const suggestions = results.map(result => { + return results.map(result => { const note = getNoteFromCache(result.id) if (!note) { throw new Error(`Note "${result.id}" not indexed`) @@ -292,8 +294,6 @@ export async function getSuggestions( } return resultNote }) - - return suggestions } /** @@ -365,6 +365,7 @@ export async function addToIndex(file: TAbstractFile): Promise { * Index a non-existing note. * Useful to find internal links that lead (yet) to nowhere * @param name + * @param parent The note referencing the */ export function addNonExistingToIndex(name: string, parent: string): void { name = removeAnchors(name) @@ -415,9 +416,11 @@ export function removeFromIndex(path: string): void { } const notesToReindex = new Set() + export function addNoteToReindex(note: TAbstractFile): void { notesToReindex.add(note) } + export async function reindexNotes(): Promise { if (settings.showIndexingNotices && notesToReindex.size > 0) { new Notice(`Omnisearch - Reindexing ${notesToReindex.size} notes`, 2000)