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