Chore - code cleaning

This commit is contained in:
Simon Cambier
2022-09-21 17:49:07 +02:00
parent 80ce347a85
commit 8dfa1810f0
6 changed files with 19 additions and 20 deletions

View File

@@ -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}

View File

@@ -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}`)) {

View File

@@ -1,7 +1,5 @@
import { EventBus } from './event-bus'
// Matches a wikiling that begins a string
export const regexWikilink = /^!?\[\[(?<name>.+?)(\|(?<alias>.+?))?\]\]/
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

View File

@@ -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()
})
}

View File

@@ -43,15 +43,19 @@ export async function loadNotesCache(): Promise<void> {
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<void> {
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<void> {
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

View File

@@ -80,7 +80,9 @@ export async function initGlobalSearchIndex(): Promise<void> {
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,7 +140,7 @@ export async function initGlobalSearchIndex(): Promise<void> {
/**
* 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<SearchResult[]> {
@@ -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<void> {
* 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<TAbstractFile>()
export function addNoteToReindex(note: TAbstractFile): void {
notesToReindex.add(note)
}
export async function reindexNotes(): Promise<void> {
if (settings.showIndexingNotices && notesToReindex.size > 0) {
new Notice(`Omnisearch - Reindexing ${notesToReindex.size} notes`, 2000)