Wip less magic strings
This commit is contained in:
@@ -243,7 +243,7 @@
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">ctrl+h</span>
|
||||
<span>to toggle context</span>
|
||||
<span>to toggle excerpt</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">esc</span><span>to close</span>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getNoteFromCache } from 'src/notes'
|
||||
import { settings, showContext } from 'src/settings'
|
||||
import { settings, showExcerpt } from 'src/settings'
|
||||
import type { ResultNote } from '../globals'
|
||||
import { getMatches } from '../search'
|
||||
import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
|
||||
@@ -29,7 +29,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if $showContext}
|
||||
{#if $showExcerpt}
|
||||
<div class="omnisearch-result__body">
|
||||
{@html cleanedContent.replace(reg, highlighter)}
|
||||
</div>
|
||||
|
||||
@@ -16,6 +16,10 @@ 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 const EventNames = {
|
||||
ToggleExcerpts: 'toggle-excerpts',
|
||||
} as const
|
||||
|
||||
export type IndexedNote = {
|
||||
path: string
|
||||
basename: string
|
||||
@@ -50,9 +54,11 @@ export type ResultNote = {
|
||||
}
|
||||
|
||||
let inComposition = false
|
||||
|
||||
export function toggleInputComposition(toggle: boolean): void {
|
||||
inComposition = toggle
|
||||
}
|
||||
|
||||
export function isInputComposition(): boolean {
|
||||
return inComposition
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Plugin, TFile } from 'obsidian'
|
||||
import { initGlobalSearchIndex } from './search'
|
||||
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
||||
import { loadSettings, settings, SettingsTab, showContext } from './settings'
|
||||
import { eventBus } from './globals'
|
||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
||||
import {eventBus, EventNames} from './globals'
|
||||
import { registerAPI } from '@vanakat/plugin-api'
|
||||
import api from './api'
|
||||
import { loadSearchHistory } from './search-history'
|
||||
@@ -32,8 +32,8 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
this.addSettingTab(new SettingsTab(this))
|
||||
eventBus.disable('vault')
|
||||
eventBus.disable('infile')
|
||||
eventBus.on('global', 'toggle-context', () => {
|
||||
showContext.set(!settings.showContext)
|
||||
eventBus.on('global', EventNames.ToggleExcerpts, () => {
|
||||
showExcerpt.set(!settings.showExcerpt)
|
||||
})
|
||||
|
||||
// Commands to display Omnisearch modals
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { App, Modal, TFile } from 'obsidian'
|
||||
import ModalVault from './components/ModalVault.svelte'
|
||||
import ModalInFile from './components/ModalInFile.svelte'
|
||||
import { eventBus, isInputComposition } from './globals'
|
||||
import {eventBus, EventNames, isInputComposition} from './globals'
|
||||
import { settings } from './settings'
|
||||
|
||||
abstract class OmnisearchModal extends Modal {
|
||||
@@ -111,7 +111,7 @@ abstract class OmnisearchModal extends Modal {
|
||||
// Context
|
||||
this.scope.register(['Ctrl'], 'h', e => {
|
||||
e.preventDefault()
|
||||
eventBus.emit('toggle-context')
|
||||
eventBus.emit(EventNames.ToggleExcerpts)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,6 @@ async function indexPDFs() {
|
||||
removeFromIndex(file.path)
|
||||
}
|
||||
await addToIndex(file)
|
||||
console.log(file.path)
|
||||
}
|
||||
if (settings.showIndexingNotices) {
|
||||
new Notice(`Omnisearch - Indexed ${files.length} PDFs`)
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface OmnisearchSettings extends WeightingSettings {
|
||||
showIndexingNotices: boolean
|
||||
ribbonIcon: boolean
|
||||
showShortName: boolean
|
||||
showContext: boolean
|
||||
showExcerpt: boolean
|
||||
showCreateButton: boolean
|
||||
CtrlJK: boolean
|
||||
CtrlNP: boolean
|
||||
@@ -29,9 +29,9 @@ export interface OmnisearchSettings extends WeightingSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* A store to reactively toggle the `showContext` setting on the fly
|
||||
* A store to reactively toggle the `showExcerpt` setting on the fly
|
||||
*/
|
||||
export const showContext = writable(false)
|
||||
export const showExcerpt = writable(false)
|
||||
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
plugin: OmnisearchPlugin
|
||||
@@ -40,8 +40,8 @@ export class SettingsTab extends PluginSettingTab {
|
||||
super(app, plugin)
|
||||
this.plugin = plugin
|
||||
|
||||
showContext.subscribe(async v => {
|
||||
settings.showContext = v
|
||||
showExcerpt.subscribe(async v => {
|
||||
settings.showExcerpt = v
|
||||
await saveSettings(this.plugin)
|
||||
})
|
||||
}
|
||||
@@ -178,13 +178,13 @@ export class SettingsTab extends PluginSettingTab {
|
||||
|
||||
// Show Context
|
||||
new Setting(containerEl)
|
||||
.setName('Show context')
|
||||
.setName('Show excerpt')
|
||||
.setDesc(
|
||||
'Shows the part of the note that matches the search. Disable this to only show filenames in results.'
|
||||
)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.showContext).onChange(async v => {
|
||||
showContext.set(v)
|
||||
toggle.setValue(settings.showExcerpt).onChange(async v => {
|
||||
showExcerpt.set(v)
|
||||
})
|
||||
)
|
||||
|
||||
@@ -303,7 +303,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
||||
showIndexingNotices: false,
|
||||
showShortName: false,
|
||||
ribbonIcon: true,
|
||||
showContext: true,
|
||||
showExcerpt: true,
|
||||
showCreateButton: false,
|
||||
|
||||
weightBasename: 2,
|
||||
@@ -323,7 +323,7 @@ export let settings = Object.assign({}, DEFAULT_SETTINGS) as OmnisearchSettings
|
||||
|
||||
export async function loadSettings(plugin: Plugin): Promise<void> {
|
||||
settings = Object.assign({}, DEFAULT_SETTINGS, await plugin.loadData())
|
||||
showContext.set(settings.showContext)
|
||||
showExcerpt.set(settings.showExcerpt)
|
||||
}
|
||||
|
||||
export async function saveSettings(plugin: Plugin): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user