#70 - Correctly toggling and saving settings.showContext
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
import ResultItemVault from './ResultItemVault.svelte'
|
||||
import { Query } from 'src/query'
|
||||
import { saveSearchHistory, searchHistory } from 'src/search-history'
|
||||
import { SearchContextType, settings } from 'src/settings'
|
||||
import { settings } from 'src/settings'
|
||||
|
||||
export let modal: OmnisearchVaultModal
|
||||
let selectedIndex = 0
|
||||
@@ -29,7 +29,6 @@
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
console.log('mount')
|
||||
await reindexNotes()
|
||||
searchQuery = searchHistory[historySearchIndex]
|
||||
eventBus.enable('vault')
|
||||
@@ -42,7 +41,6 @@
|
||||
eventBus.on('vault', 'arrow-down', () => moveIndex(1))
|
||||
eventBus.on('vault', 'prev-search-history', prevSearchHistory)
|
||||
eventBus.on('vault', 'next-search-history', nextSearchHistory)
|
||||
eventBus.on('vault', 'toggle-context', toggleContext)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
@@ -62,16 +60,6 @@
|
||||
searchQuery = searchHistory[historySearchIndex]
|
||||
}
|
||||
|
||||
function toggleContext() {
|
||||
settings.update(s => {
|
||||
s.showContext =
|
||||
s.showContext === SearchContextType.None
|
||||
? SearchContextType.Simple
|
||||
: SearchContextType.None
|
||||
return s
|
||||
})
|
||||
}
|
||||
|
||||
async function updateResults() {
|
||||
query = new Query(searchQuery)
|
||||
resultNotes = (await getSuggestions(query)).sort(
|
||||
@@ -108,7 +96,6 @@
|
||||
async function createNoteAndCloseModal(opt?: {
|
||||
newLeaf: boolean
|
||||
}): Promise<void> {
|
||||
console.log(opt)
|
||||
try {
|
||||
await createNote(searchQuery, opt?.newLeaf)
|
||||
} catch (e) {
|
||||
@@ -203,8 +190,8 @@
|
||||
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">alt ↑↓</span><span
|
||||
>to cycle history</span>
|
||||
<span class="prompt-instruction-command">alt ↑↓</span>
|
||||
<span>to cycle history</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
||||
@@ -236,8 +223,8 @@
|
||||
<span>to insert a link</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">ctrl+h</span><span
|
||||
>to toggle context</span>
|
||||
<span class="prompt-instruction-command">ctrl+h</span>
|
||||
<span>to toggle context</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 { SearchContextType, settings } from 'src/settings'
|
||||
import { settings } 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 $settings.showContext !== SearchContextType.None}
|
||||
{#if $settings.showContext}
|
||||
<div class="omnisearch-result__body">
|
||||
{@html cleanedContent.replace(reg, highlighter)}
|
||||
</div>
|
||||
|
||||
@@ -43,6 +43,13 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
this.addSettingTab(new SettingsTab(this))
|
||||
eventBus.disable('vault')
|
||||
eventBus.disable('infile')
|
||||
eventBus.on('global', 'toggle-context', () => {
|
||||
settings.update(s => {
|
||||
s.showContext = !s.showContext
|
||||
return s
|
||||
})
|
||||
this.saveData(get(settings))
|
||||
})
|
||||
|
||||
// Commands to display Omnisearch modals
|
||||
this.addCommand({
|
||||
|
||||
@@ -16,17 +16,12 @@ export interface OmnisearchSettings extends WeightingSettings {
|
||||
showIndexingNotices: boolean
|
||||
ribbonIcon: boolean
|
||||
showShortName: boolean
|
||||
showContext: SearchContextType
|
||||
showContext: boolean
|
||||
CtrlJK: boolean
|
||||
CtrlNP: boolean
|
||||
storeIndexInFile: boolean
|
||||
}
|
||||
|
||||
export enum SearchContextType {
|
||||
None,
|
||||
Simple,
|
||||
}
|
||||
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
plugin: OmnisearchPlugin
|
||||
|
||||
@@ -131,6 +126,25 @@ export class SettingsTab extends PluginSettingTab {
|
||||
})
|
||||
)
|
||||
|
||||
// Show Context
|
||||
new Setting(containerEl)
|
||||
.setName('Show context')
|
||||
.setDesc(
|
||||
'Shows the part of the note that matches the search. Disable this to only show filenames in results.'
|
||||
)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(get(settings).showContext).onChange(async v => {
|
||||
settings.update(s => {
|
||||
s.showContext = v
|
||||
return s
|
||||
})
|
||||
await saveSettings(this.plugin)
|
||||
if (v) {
|
||||
this.plugin.addRibbonButton()
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
// Show notices
|
||||
new Setting(containerEl)
|
||||
.setName('Show indexing notices')
|
||||
@@ -243,7 +257,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
||||
showIndexingNotices: false,
|
||||
showShortName: false,
|
||||
ribbonIcon: true,
|
||||
showContext: SearchContextType.Simple,
|
||||
showContext: true,
|
||||
|
||||
weightBasename: 2,
|
||||
weightH1: 1.5,
|
||||
|
||||
Reference in New Issue
Block a user