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