This commit is contained in:
@@ -14,6 +14,9 @@ export const highlightClass = 'suggestion-highlight omnisearch-highlight'
|
||||
|
||||
export const eventBus = new EventBus()
|
||||
|
||||
export const searchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
||||
export const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
||||
|
||||
export type SearchNote = {
|
||||
path: string
|
||||
basename: string
|
||||
|
||||
24
src/notes.ts
24
src/notes.ts
@@ -1,10 +1,9 @@
|
||||
import { MarkdownView, TFile, type CachedMetadata } from 'obsidian'
|
||||
import {
|
||||
MarkdownView,
|
||||
TFile,
|
||||
WorkspaceLeaf,
|
||||
type CachedMetadata,
|
||||
} from 'obsidian'
|
||||
import type { IndexedNote, ResultNote } from './globals'
|
||||
notesCacheFilePath,
|
||||
type IndexedNote,
|
||||
type ResultNote,
|
||||
} from './globals'
|
||||
import { stringsToRegex } from './utils'
|
||||
import { settings } from './settings'
|
||||
|
||||
@@ -15,8 +14,6 @@ import { settings } from './settings'
|
||||
*/
|
||||
export let notesCache: Record<string, IndexedNote> = {}
|
||||
|
||||
const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
||||
|
||||
export function resetNotesCache(): void {
|
||||
notesCache = {}
|
||||
}
|
||||
@@ -67,7 +64,11 @@ export async function openNote(
|
||||
let alreadyOpenAndPinned = false
|
||||
app.workspace.iterateAllLeaves(leaf => {
|
||||
if (leaf.view instanceof MarkdownView) {
|
||||
if (!newPane && leaf.getViewState().state?.file === item.path && leaf.getViewState()?.pinned) {
|
||||
if (
|
||||
!newPane &&
|
||||
leaf.getViewState().state?.file === item.path &&
|
||||
leaf.getViewState()?.pinned
|
||||
) {
|
||||
app.workspace.setActiveLeaf(leaf, false, true)
|
||||
alreadyOpenAndPinned = true
|
||||
}
|
||||
@@ -95,7 +96,10 @@ export async function openNote(
|
||||
|
||||
export async function createNote(name: string): Promise<void> {
|
||||
try {
|
||||
const file = await app.vault.create(`${app.vault.getConfig('newFileFolderPath')}/${name}.md`, '')
|
||||
const file = await app.vault.create(
|
||||
`${app.vault.getConfig('newFileFolderPath')}/${name}.md`,
|
||||
'',
|
||||
)
|
||||
await app.workspace.openLinkText(file.path, '')
|
||||
const view = app.workspace.getActiveViewOfType(MarkdownView)
|
||||
if (!view) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Notice, TAbstractFile, TFile } from 'obsidian'
|
||||
import MiniSearch, { type Options, type SearchResult } from 'minisearch'
|
||||
import {
|
||||
chsRegex,
|
||||
searchIndexFilePath,
|
||||
SPACE_OR_PUNCTUATION,
|
||||
type IndexedNote,
|
||||
type ResultNote,
|
||||
@@ -33,7 +34,6 @@ import {
|
||||
|
||||
let minisearchInstance: MiniSearch<IndexedNote>
|
||||
let isIndexChanged: boolean
|
||||
const searchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
||||
|
||||
const tokenize = (text: string): string[] => {
|
||||
const tokens = text.split(SPACE_OR_PUNCTUATION)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian'
|
||||
import { notesCacheFilePath, searchIndexFilePath } from './globals'
|
||||
import type OmnisearchPlugin from './main'
|
||||
|
||||
interface WeightingSettings {
|
||||
@@ -51,11 +52,15 @@ export class SettingsTab extends PluginSettingTab {
|
||||
)
|
||||
|
||||
// Ignore diacritics
|
||||
const diacriticsDesc = new DocumentFragment()
|
||||
diacriticsDesc.createSpan({}, span => {
|
||||
span.innerHTML = `Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky".<br/>
|
||||
<strong>Needs a restart to fully take effect.</strong>
|
||||
`
|
||||
})
|
||||
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.',
|
||||
)
|
||||
.setDesc(diacriticsDesc)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
|
||||
settings.ignoreDiacritics = v
|
||||
@@ -63,13 +68,20 @@ export class SettingsTab extends PluginSettingTab {
|
||||
}),
|
||||
)
|
||||
|
||||
const serializedIndexDesc = new DocumentFragment()
|
||||
serializedIndexDesc.createSpan({}, span => {
|
||||
span.innerHTML = `The search index is stored on disk, instead of being rebuilt at every startup. This results in faster loading times for bigger vaults and mobile devices.<br />
|
||||
<em>⚠️ Note: the index can become corrupted - if you notice any issue, disable and re-enable this option to clear the cache.</em><br/>
|
||||
<strong>Needs a restart to fully take effect.</strong>
|
||||
`
|
||||
})
|
||||
new Setting(containerEl)
|
||||
.setName('Store index in file')
|
||||
.setDesc(
|
||||
'Index is stored on disk, instead of being rebuilt at every startup.',
|
||||
)
|
||||
.setName('EXPERIMENTAL - Store index in file')
|
||||
.setDesc(serializedIndexDesc)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.storeIndexInFile).onChange(async v => {
|
||||
app.vault.adapter.remove(notesCacheFilePath)
|
||||
app.vault.adapter.remove(searchIndexFilePath)
|
||||
settings.storeIndexInFile = v
|
||||
await saveSettings(this.plugin)
|
||||
}),
|
||||
@@ -173,7 +185,7 @@ export class SettingsTab extends PluginSettingTab {
|
||||
|
||||
export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
||||
respectExcluded: true,
|
||||
ignoreDiacritics: false,
|
||||
ignoreDiacritics: true,
|
||||
|
||||
showIndexingNotices: false,
|
||||
showShortName: false,
|
||||
|
||||
Reference in New Issue
Block a user