#58 - index other files than .md

Also, reverted 66e1d2d334 to only make showContext reactive
This commit is contained in:
Simon Cambier
2022-09-23 20:50:55 +02:00
parent 0da61668b0
commit eacb53dc88
9 changed files with 104 additions and 107 deletions

View File

@@ -6,7 +6,7 @@
import { eventBus, type ResultNote } from 'src/globals' import { eventBus, type ResultNote } from 'src/globals'
import { createNote, openNote } from 'src/notes' import { createNote, openNote } from 'src/notes'
import { getSuggestions, reindexNotes } from 'src/search' import { getSuggestions, reindexNotes } from 'src/search'
import { getCtrlKeyLabel, loopIndex } from 'src/utils' import { getCtrlKeyLabel, getExtension, loopIndex } from 'src/utils'
import { OmnisearchInFileModal, type OmnisearchVaultModal } from 'src/modals' import { OmnisearchInFileModal, type OmnisearchVaultModal } from 'src/modals'
import ResultItemVault from './ResultItemVault.svelte' import ResultItemVault from './ResultItemVault.svelte'
import { Query } from 'src/query' import { Query } from 'src/query'
@@ -20,7 +20,6 @@
let resultNotes: ResultNote[] = [] let resultNotes: ResultNote[] = []
let query: Query let query: Query
$: selectedNote = resultNotes[selectedIndex] $: selectedNote = resultNotes[selectedIndex]
// $: lastSearch = lastSearches[lastSearchIndex]
$: if (searchQuery) { $: if (searchQuery) {
updateResults() updateResults()
@@ -94,6 +93,10 @@
openNote(note, newPane) openNote(note, newPane)
} }
async function onClickCreateNote(e: MouseEvent) {
await createNoteAndCloseModal()
}
async function createNoteAndCloseModal(opt?: { async function createNoteAndCloseModal(opt?: {
newLeaf: boolean newLeaf: boolean
}): Promise<void> { }): Promise<void> {
@@ -123,7 +126,7 @@
if (file && active) { if (file && active) {
link = app.fileManager.generateMarkdownLink(file, active.path) link = app.fileManager.generateMarkdownLink(file, active.path)
} else { } else {
link = `[[${selectedNote.basename}.md]]` link = `[[${selectedNote.basename}.${getExtension(selectedNote.path)}]]`
} }
// Inject link // Inject link
@@ -172,8 +175,8 @@
value="{searchQuery}" value="{searchQuery}"
on:input="{e => (searchQuery = e.detail)}" on:input="{e => (searchQuery = e.detail)}"
placeholder="Omnisearch - Vault"> placeholder="Omnisearch - Vault">
{#if $settings.showCreateButton} {#if settings.showCreateButton}
<button on:click="{createNoteAndCloseModal}">Create note</button> <button on:click="{onClickCreateNote}">Create note</button>
{/if} {/if}
</InputSearch> </InputSearch>

View File

@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { getNoteFromCache } from 'src/notes' import { getNoteFromCache } from 'src/notes'
import { settings } from 'src/settings' import { settings, showContext } from 'src/settings'
import type { ResultNote } from '../globals' import type { ResultNote } from '../globals'
import { getMatches } from '../search' import { getMatches } from '../search'
import { highlighter, makeExcerpt, stringsToRegex } from '../utils' import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
@@ -13,7 +13,7 @@
$: matches = getMatches(note.content, reg) $: matches = getMatches(note.content, reg)
$: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1) $: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
$: glyph = getNoteFromCache(note.path)?.doesNotExist $: glyph = getNoteFromCache(note.path)?.doesNotExist
$: title = $settings.showShortName ? note.basename : note.path $: title = settings.showShortName ? note.basename : note.path
</script> </script>
<ResultItemContainer id={note.path} {selected} on:mousemove on:click {glyph}> <ResultItemContainer id={note.path} {selected} on:mousemove on:click {glyph}>
@@ -29,7 +29,7 @@
{/if} {/if}
</div> </div>
{#if $settings.showContext} {#if $showContext}
<div class="omnisearch-result__body"> <div class="omnisearch-result__body">
{@html cleanedContent.replace(reg, highlighter)} {@html cleanedContent.replace(reg, highlighter)}
</div> </div>

View File

@@ -6,20 +6,12 @@ import {
removeFromIndex, removeFromIndex,
} from './search' } from './search'
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals' import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
import { loadSettings, settings, SettingsTab } from './settings' import { loadSettings, settings, SettingsTab, showContext } from './settings'
import { eventBus } from './globals' import { eventBus } from './globals'
import { registerAPI } from '@vanakat/plugin-api' import { registerAPI } from '@vanakat/plugin-api'
import api from './api' import api from './api'
import { loadSearchHistory } from './search-history' import { loadSearchHistory } from './search-history'
import { get } from 'svelte/store' import { isFileIndexable } from './utils'
// let mainWindow: { on: any; off: any } | null = null
// try {
// mainWindow = require('electron').remote.getCurrentWindow()
// }
// catch (e) {
// console.log("Can't load electron, mobile platform")
// }
function _registerAPI(plugin: OmnisearchPlugin): void { function _registerAPI(plugin: OmnisearchPlugin): void {
registerAPI('omnisearch', api, plugin as any) registerAPI('omnisearch', api, plugin as any)
@@ -31,12 +23,15 @@ function _registerAPI(plugin: OmnisearchPlugin): void {
export default class OmnisearchPlugin extends Plugin { export default class OmnisearchPlugin extends Plugin {
async onload(): Promise<void> { async onload(): Promise<void> {
// additional files to index by Omnisearch
await loadSettings(this) await loadSettings(this)
this.registerExtensions(settings.indexedFileTypes, 'markdown')
await loadSearchHistory() await loadSearchHistory()
_registerAPI(this) _registerAPI(this)
if (get(settings).ribbonIcon) { if (settings.ribbonIcon) {
this.addRibbonButton() this.addRibbonButton()
} }
@@ -44,11 +39,7 @@ export default class OmnisearchPlugin extends Plugin {
eventBus.disable('vault') eventBus.disable('vault')
eventBus.disable('infile') eventBus.disable('infile')
eventBus.on('global', 'toggle-context', () => { eventBus.on('global', 'toggle-context', () => {
settings.update(s => { showContext.set(!settings.showContext)
s.showContext = !s.showContext
return s
})
this.saveData(get(settings))
}) })
// Commands to display Omnisearch modals // Commands to display Omnisearch modals
@@ -87,7 +78,7 @@ export default class OmnisearchPlugin extends Plugin {
) )
this.registerEvent( this.registerEvent(
this.app.vault.on('rename', async (file, oldPath) => { this.app.vault.on('rename', async (file, oldPath) => {
if (file instanceof TFile && file.path.endsWith('.md')) { if (file instanceof TFile && isFileIndexable(file.path)) {
removeFromIndex(oldPath) removeFromIndex(oldPath)
await addToIndex(file) await addToIndex(file)
} }

View File

@@ -3,7 +3,6 @@ import ModalVault from './components/ModalVault.svelte'
import ModalInFile from './components/ModalInFile.svelte' import ModalInFile from './components/ModalInFile.svelte'
import { eventBus, isInputComposition } from './globals' import { eventBus, isInputComposition } from './globals'
import { settings } from './settings' import { settings } from './settings'
import { get } from 'svelte/store'
abstract class OmnisearchModal extends Modal { abstract class OmnisearchModal extends Modal {
protected constructor(app: App) { protected constructor(app: App) {
@@ -38,7 +37,7 @@ abstract class OmnisearchModal extends Modal {
] as const) { ] as const) {
for (const modifier of ['Ctrl', 'Meta'] as const) { for (const modifier of ['Ctrl', 'Meta'] as const) {
this.scope.register([modifier], key.k, e => { this.scope.register([modifier], key.k, e => {
if (get(settings).CtrlJK && this.app.vault.getConfig('vimMode')) { if (settings.CtrlJK && this.app.vault.getConfig('vimMode')) {
e.preventDefault() e.preventDefault()
eventBus.emit('arrow-' + key.dir) eventBus.emit('arrow-' + key.dir)
} }
@@ -53,7 +52,7 @@ abstract class OmnisearchModal extends Modal {
] as const) { ] as const) {
for (const modifier of ['Ctrl', 'Meta'] as const) { for (const modifier of ['Ctrl', 'Meta'] as const) {
this.scope.register([modifier], key.k, e => { this.scope.register([modifier], key.k, e => {
if (get(settings).CtrlNP && this.app.vault.getConfig('vimMode')) { if (settings.CtrlNP && this.app.vault.getConfig('vimMode')) {
e.preventDefault() e.preventDefault()
eventBus.emit('arrow-' + key.dir) eventBus.emit('arrow-' + key.dir)
} }

View File

@@ -11,7 +11,6 @@ import {
} from './globals' } from './globals'
import { stringsToRegex, wait } from './utils' import { stringsToRegex, wait } from './utils'
import { settings } from './settings' import { settings } from './settings'
import { get } from 'svelte/store'
/** /**
* This is an in-memory cache of the notes, with all their computed fields * This is an in-memory cache of the notes, with all their computed fields
@@ -26,7 +25,7 @@ export function resetNotesCache(): void {
export async function loadNotesCache(): Promise<void> { export async function loadNotesCache(): Promise<void> {
if ( if (
get(settings).storeIndexInFile && settings.storeIndexInFile &&
(await app.vault.adapter.exists(notesCacheFilePath)) (await app.vault.adapter.exists(notesCacheFilePath))
) { ) {
try { try {

View File

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

View File

@@ -12,13 +12,14 @@ import {
extractHeadingsFromCache, extractHeadingsFromCache,
getAliasesFromMetadata, getAliasesFromMetadata,
getTagsFromMetadata, getTagsFromMetadata,
isFileIndexable,
removeDiacritics, removeDiacritics,
stringsToRegex, stringsToRegex,
stripMarkdownCharacters, stripMarkdownCharacters,
wait, wait,
} from './utils' } from './utils'
import type { Query } from './query' import type { Query } from './query'
import { settings as storeSettings } from './settings' import { settings } from './settings'
import { import {
removeNoteFromCache, removeNoteFromCache,
getNoteFromCache, getNoteFromCache,
@@ -31,13 +32,9 @@ import {
saveNotesCacheToFile, saveNotesCacheToFile,
isCacheOutdated, isCacheOutdated,
} from './notes' } from './notes'
import { get } from 'svelte/store'
let minisearchInstance: MiniSearch<IndexedNote> let minisearchInstance: MiniSearch<IndexedNote>
let isIndexChanged: boolean let isIndexChanged: boolean
const settings = get(storeSettings)
const tokenize = (text: string): string[] => { const tokenize = (text: string): string[] => {
const tokens = text.split(SPACE_OR_PUNCTUATION) const tokens = text.split(SPACE_OR_PUNCTUATION)
const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch'] const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch']
@@ -95,7 +92,7 @@ export async function initGlobalSearchIndex(): Promise<void> {
// Index files that are already present // Index files that are already present
const start = new Date().getTime() const start = new Date().getTime()
const allFiles = app.vault.getMarkdownFiles() const allFiles = app.vault.getFiles().filter(f => isFileIndexable(f.path))
let files let files
let notesSuffix let notesSuffix
@@ -302,7 +299,7 @@ export async function getSuggestions(
* @returns * @returns
*/ */
export async function addToIndex(file: TAbstractFile): Promise<void> { export async function addToIndex(file: TAbstractFile): Promise<void> {
if (!(file instanceof TFile) || file.extension !== 'md') { if (!(file instanceof TFile) || !isFileIndexable(file.path)) {
return return
} }
@@ -396,8 +393,8 @@ export function addNonExistingToIndex(name: string, parent: string): void {
* @param path * @param path
*/ */
export function removeFromIndex(path: string): void { export function removeFromIndex(path: string): void {
if (!path.endsWith('.md')) { if (!isFileIndexable(path)) {
console.info(`"${path}" is not a .md file`) console.info(`"${path}" is not an indexable file`)
return return
} }
const note = getNoteFromCache(path) const note = getNoteFromCache(path)

View File

@@ -1,7 +1,7 @@
import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian' import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian'
import { writable } from 'svelte/store'
import { notesCacheFilePath, searchIndexFilePath } from './globals' import { notesCacheFilePath, searchIndexFilePath } from './globals'
import type OmnisearchPlugin from './main' import type OmnisearchPlugin from './main'
import { get, writable } from 'svelte/store'
interface WeightingSettings { interface WeightingSettings {
weightBasename: number weightBasename: number
@@ -13,6 +13,9 @@ interface WeightingSettings {
export interface OmnisearchSettings extends WeightingSettings { export interface OmnisearchSettings extends WeightingSettings {
respectExcluded: boolean respectExcluded: boolean
ignoreDiacritics: boolean ignoreDiacritics: boolean
indexedFileTypes: string[]
storeIndexInFile: boolean
showIndexingNotices: boolean showIndexingNotices: boolean
ribbonIcon: boolean ribbonIcon: boolean
showShortName: boolean showShortName: boolean
@@ -20,15 +23,24 @@ export interface OmnisearchSettings extends WeightingSettings {
showCreateButton: boolean showCreateButton: boolean
CtrlJK: boolean CtrlJK: boolean
CtrlNP: boolean CtrlNP: boolean
storeIndexInFile: boolean
} }
/**
* A store to reactively toggle the `showContext` setting on the fly
*/
export const showContext = writable(false)
export class SettingsTab extends PluginSettingTab { export class SettingsTab extends PluginSettingTab {
plugin: OmnisearchPlugin plugin: OmnisearchPlugin
constructor(plugin: OmnisearchPlugin) { constructor(plugin: OmnisearchPlugin) {
super(app, plugin) super(app, plugin)
this.plugin = plugin this.plugin = plugin
showContext.subscribe(async v => {
settings.showContext = v
await saveSettings(this.plugin)
})
} }
display(): void { display(): void {
@@ -49,11 +61,8 @@ export class SettingsTab extends PluginSettingTab {
'Files that are in Obsidian\'s "Options > Files & Links > Excluded Files" list will be downranked in results.' 'Files that are in Obsidian\'s "Options > Files & Links > Excluded Files" list will be downranked in results.'
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).respectExcluded).onChange(async v => { toggle.setValue(settings.respectExcluded).onChange(async v => {
settings.update(s => { settings.respectExcluded = v
s.respectExcluded = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -68,15 +77,33 @@ export class SettingsTab extends PluginSettingTab {
.setName('Ignore diacritics') .setName('Ignore diacritics')
.setDesc(diacriticsDesc) .setDesc(diacriticsDesc)
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).ignoreDiacritics).onChange(async v => { toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
settings.update(s => { settings.ignoreDiacritics = v
s.ignoreDiacritics = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
// Additional files to index
const indexedFileTypesDesc = new DocumentFragment()
indexedFileTypesDesc.createSpan({}, span => {
span.innerHTML = `In addition to standard <code>md</code> files, Omnisearch can also index other plain text files.<br/>
Add extensions separated by a space. Example: <code>txt org</code>.<br />
This setting will also add these files in the navigation, and they will be treated as markdown.<br />
<strong>Needs a restart to fully take effect.</strong>`
})
new Setting(containerEl)
.setName('Additional files to index')
.setDesc(indexedFileTypesDesc)
.addText(component => {
component
.setValue(settings.indexedFileTypes.join(' '))
.setPlaceholder('Example: txt org')
.onChange(async v => {
settings.indexedFileTypes = v.split(' ')
await saveSettings(this.plugin)
})
})
// Store index // Store index
const serializedIndexDesc = new DocumentFragment() const serializedIndexDesc = new DocumentFragment()
serializedIndexDesc.createSpan({}, span => { serializedIndexDesc.createSpan({}, span => {
@@ -91,13 +118,10 @@ export class SettingsTab extends PluginSettingTab {
.setName('EXPERIMENTAL - Store index in file') .setName('EXPERIMENTAL - Store index in file')
.setDesc(serializedIndexDesc) .setDesc(serializedIndexDesc)
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).storeIndexInFile).onChange(async v => { toggle.setValue(settings.storeIndexInFile).onChange(async v => {
await app.vault.adapter.remove(notesCacheFilePath) await app.vault.adapter.remove(notesCacheFilePath)
await app.vault.adapter.remove(searchIndexFilePath) await app.vault.adapter.remove(searchIndexFilePath)
settings.update(s => { settings.storeIndexInFile = v
s.storeIndexInFile = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -115,11 +139,8 @@ export class SettingsTab extends PluginSettingTab {
'Add a button on the sidebar to open the Vault search modal. Needs a restart to remove the button.' 'Add a button on the sidebar to open the Vault search modal. Needs a restart to remove the button.'
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).ribbonIcon).onChange(async v => { toggle.setValue(settings.ribbonIcon).onChange(async v => {
settings.update(s => { settings.ribbonIcon = v
s.ribbonIcon = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
if (v) { if (v) {
this.plugin.addRibbonButton() this.plugin.addRibbonButton()
@@ -134,15 +155,8 @@ export class SettingsTab extends PluginSettingTab {
'Shows the part of the note that matches the search. Disable this to only show filenames in results.' 'Shows the part of the note that matches the search. Disable this to only show filenames in results.'
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).showContext).onChange(async v => { toggle.setValue(settings.showContext).onChange(async v => {
settings.update(s => { showContext.set(v)
s.showContext = v
return s
})
await saveSettings(this.plugin)
if (v) {
this.plugin.addRibbonButton()
}
}) })
) )
@@ -156,11 +170,8 @@ export class SettingsTab extends PluginSettingTab {
.setName('Show "Create note" button') .setName('Show "Create note" button')
.setDesc(createBtnDesc) .setDesc(createBtnDesc)
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).showCreateButton).onChange(async v => { toggle.setValue(settings.showCreateButton).onChange(async v => {
settings.update(s => { settings.showCreateButton = v
s.showCreateButton = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -170,11 +181,8 @@ export class SettingsTab extends PluginSettingTab {
.setName('Show indexing notices') .setName('Show indexing notices')
.setDesc('Shows a notice when indexing is done, usually at startup.') .setDesc('Shows a notice when indexing is done, usually at startup.')
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).showIndexingNotices).onChange(async v => { toggle.setValue(settings.showIndexingNotices).onChange(async v => {
settings.update(s => { settings.showIndexingNotices = v
s.showIndexingNotices = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -186,11 +194,8 @@ export class SettingsTab extends PluginSettingTab {
'In the search results, only show the note name, without the full path.' 'In the search results, only show the note name, without the full path.'
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).showShortName).onChange(async v => { toggle.setValue(settings.showShortName).onChange(async v => {
settings.update(s => { settings.showShortName = v
s.showShortName = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -230,11 +235,8 @@ export class SettingsTab extends PluginSettingTab {
'Use [Ctrl/Cmd]+j/k to navigate up/down in the results, if Vim mode is enabled' 'Use [Ctrl/Cmd]+j/k to navigate up/down in the results, if Vim mode is enabled'
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).CtrlJK).onChange(async v => { toggle.setValue(settings.CtrlJK).onChange(async v => {
settings.update(s => { settings.CtrlJK = v
s.CtrlJK = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -244,11 +246,8 @@ export class SettingsTab extends PluginSettingTab {
'Use [Ctrl/Cmd]+n/p to navigate up/down in the results, if Vim mode is enabled' 'Use [Ctrl/Cmd]+n/p to navigate up/down in the results, if Vim mode is enabled'
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(get(settings).CtrlNP).onChange(async v => { toggle.setValue(settings.CtrlNP).onChange(async v => {
settings.update(s => { settings.CtrlNP = v
s.CtrlNP = v
return s
})
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -258,13 +257,10 @@ export class SettingsTab extends PluginSettingTab {
weightSlider(cb: SliderComponent, key: keyof WeightingSettings): void { weightSlider(cb: SliderComponent, key: keyof WeightingSettings): void {
cb.setLimits(1, 3, 0.1) cb.setLimits(1, 3, 0.1)
cb.setValue(get(settings)[key]) cb.setValue(settings[key])
cb.setDynamicTooltip() cb.setDynamicTooltip()
cb.onChange(v => { cb.onChange(v => {
settings.update(s => { settings[key] = v
s[key] = v
return s
})
saveSettings(this.plugin) saveSettings(this.plugin)
}) })
} }
@@ -273,6 +269,7 @@ export class SettingsTab extends PluginSettingTab {
export const DEFAULT_SETTINGS: OmnisearchSettings = { export const DEFAULT_SETTINGS: OmnisearchSettings = {
respectExcluded: true, respectExcluded: true,
ignoreDiacritics: true, ignoreDiacritics: true,
indexedFileTypes: [] as string[],
showIndexingNotices: false, showIndexingNotices: false,
showShortName: false, showShortName: false,
@@ -291,14 +288,13 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
storeIndexInFile: false, storeIndexInFile: false,
} as const } as const
export const settings = writable( export let settings = Object.assign({}, DEFAULT_SETTINGS) as OmnisearchSettings
Object.assign({}, DEFAULT_SETTINGS) as OmnisearchSettings
)
export async function loadSettings(plugin: Plugin): Promise<void> { export async function loadSettings(plugin: Plugin): Promise<void> {
settings.set(Object.assign({}, DEFAULT_SETTINGS, await plugin.loadData())) settings = Object.assign({}, DEFAULT_SETTINGS, await plugin.loadData())
showContext.set(settings.showContext)
} }
export async function saveSettings(plugin: Plugin): Promise<void> { export async function saveSettings(plugin: Plugin): Promise<void> {
await plugin.saveData(get(settings)) await plugin.saveData(settings)
} }

View File

@@ -9,6 +9,7 @@ import {
regexYaml, regexYaml,
} from './globals' } from './globals'
import type { SearchMatch } from './globals' import type { SearchMatch } from './globals'
import { settings } from './settings'
export function highlighter(str: string): string { export function highlighter(str: string): string {
return `<span class="${highlightClass}">${str}</span>` return `<span class="${highlightClass}">${str}</span>`
@@ -170,3 +171,15 @@ export function removeDiacritics(str: string): string {
export function getCtrlKeyLabel(): 'ctrl' | '⌘' { export function getCtrlKeyLabel(): 'ctrl' | '⌘' {
return Platform.isMacOS ? '⌘' : 'ctrl' return Platform.isMacOS ? '⌘' : 'ctrl'
} }
export function isFileIndexable(path: string): boolean {
return (
path.endsWith('.md') ||
settings.indexedFileTypes.some(t => path.endsWith(`.${t}`))
)
}
export function getExtension(path: string): string {
const split = path.split('.')
return split[split.length - 1]
}