#53 - Fixed some highlighting issues

This commit is contained in:
Simon Cambier
2022-06-08 21:54:27 +02:00
parent 3cfad5c414
commit 8f954a3cda
4 changed files with 33 additions and 26 deletions

View File

@@ -22,13 +22,16 @@ export function resetNotesCache(): void {
}
export async function loadNotesCache(): Promise<void> {
if (settings.storeIndexInFile && await app.vault.adapter.exists(notesCacheFilePath)) {
if (
settings.storeIndexInFile &&
(await app.vault.adapter.exists(notesCacheFilePath))
) {
try {
const json = await app.vault.adapter.read(notesCacheFilePath)
notesCache = JSON.parse(json)
console.log('Notes cache loaded from the file')
}
catch(e) {
catch (e) {
console.trace('Could not load Notes cache from the file')
console.error(e)
}

View File

@@ -1,4 +1,5 @@
import { stripSurroundingQuotes } from './utils'
import { settings } from './settings'
import { removeDiacritics, stripSurroundingQuotes } from './utils'
import { parseQuery } from './vendor/parse-query'
type QueryToken = {
@@ -21,6 +22,7 @@ export class Query {
public exclusions: QueryToken[] = []
constructor(text = '') {
if (settings.ignoreDiacritics) text = removeDiacritics(text)
const tokens = parseQuery(text.toLowerCase(), { tokenize: true })
this.exclusions = tokens.exclude.text
.map(this.formatToken)
@@ -48,5 +50,3 @@ export class Query {
}
}
}

View File

@@ -27,7 +27,7 @@ import {
getNonExistingNotesFromCache,
loadNotesCache,
saveNotesCacheToFile,
isCacheOutdated
isCacheOutdated,
} from './notes'
let minisearchInstance: MiniSearch<IndexedNote>
@@ -53,7 +53,7 @@ const tokenize = (text: string): string[] => {
export async function initGlobalSearchIndex(): Promise<void> {
const options = {
tokenize,
processTerm: term =>
processTerm: (term: string) =>
settings.ignoreDiacritics ? removeDiacritics(term) : term,
idField: 'path',
fields: [
@@ -66,14 +66,17 @@ export async function initGlobalSearchIndex(): Promise<void> {
],
}
if (settings.storeIndexInFile && await app.vault.adapter.exists(searchIndexFilePath)) {
if (
settings.storeIndexInFile &&
(await app.vault.adapter.exists(searchIndexFilePath))
) {
try {
const json = await app.vault.adapter.read(searchIndexFilePath)
minisearchInstance = MiniSearch.loadJSON(json, options)
console.log('MiniSearch index loaded from the file')
await loadNotesCache()
}
catch(e) {
catch (e) {
console.trace('Could not load MiniSearch index from the file')
console.error(e)
}
@@ -94,7 +97,8 @@ export async function initGlobalSearchIndex(): Promise<void> {
if (settings.storeIndexInFile) {
files = allFiles.filter(file => isCacheOutdated(file))
notesSuffix = 'modified notes'
} else {
}
else {
files = allFiles
notesSuffix = 'notes'
}

View File

@@ -71,17 +71,17 @@ export class SettingsTab extends PluginSettingTab {
)
// Ignore diacritics
// new Setting(containerEl)
// .setName('Ignore diacritics')
// .setDesc(
// 'Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky". Needs a restart to take effect.',
// )
// .addToggle(toggle =>
// toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
// settings.ignoreDiacritics = v
// await saveSettings(this.plugin)
// }),
// )
new Setting(containerEl)
.setName('Ignore diacritics')
.setDesc(
'EXPERIMENTAL - Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky". Needs a restart to take effect.',
)
.addToggle(toggle =>
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
settings.ignoreDiacritics = v
await saveSettings(this.plugin)
}),
)
new Setting(containerEl)
.setName('Store index in file')
@@ -194,7 +194,7 @@ export class SettingsTab extends PluginSettingTab {
export const DEFAULT_SETTINGS: OmnisearchSettings = {
respectExcluded: true,
reindexInRealTime: false,
ignoreDiacritics: true,
ignoreDiacritics: false,
showIndexingNotices: false,
showShortName: false,