Fixed #59 - Add a setting to display the short form of links in search results

This commit is contained in:
Simon Cambier
2022-06-03 23:31:55 +02:00
parent d625ae38e1
commit 13ff1e5079
3 changed files with 63 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import { getNoteFromCache } from "src/notes" import { getNoteFromCache } from "src/notes"
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"
@@ -12,11 +13,12 @@ $: reg = stringsToRegex(note.foundWords)
$: 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
</script> </script>
<ResultItemContainer id={note.path} {selected} on:mousemove on:click {glyph}> <ResultItemContainer id={note.path} {selected} on:mousemove on:click {glyph}>
<span class="omnisearch-result__title"> <span class="omnisearch-result__title">
{@html note.basename.replace(reg, highlighter)} {@html title.replace(reg, highlighter)}
</span> </span>
{#if matches.length > 0} {#if matches.length > 0}

View File

@@ -252,7 +252,7 @@ export async function addToIndex(file: TAbstractFile): Promise<void> {
// Make the document and index it // Make the document and index it
const note: IndexedNote = { const note: IndexedNote = {
basename: file.path, basename: file.basename,
content, content,
path: file.path, path: file.path,
aliases: getAliasesFromMetadata(metadata).join(''), aliases: getAliasesFromMetadata(metadata).join(''),

View File

@@ -9,9 +9,10 @@ interface WeightingSettings {
} }
export interface OmnisearchSettings extends WeightingSettings { export interface OmnisearchSettings extends WeightingSettings {
showIndexingNotices: boolean
respectExcluded: boolean respectExcluded: boolean
reindexInRealTime: boolean reindexInRealTime: boolean
showIndexingNotices: boolean
showShortName: boolean
CtrlJK: boolean CtrlJK: boolean
CtrlNP: boolean CtrlNP: boolean
} }
@@ -28,19 +29,31 @@ export class SettingsTab extends PluginSettingTab {
const { containerEl } = this const { containerEl } = this
containerEl.empty() containerEl.empty()
// Title // Settings main title
containerEl.createEl('h2', { text: 'Omnisearch settings' }) containerEl.createEl('h2', { text: 'Omnisearch settings' })
// Show notices // #region Behavior
new Setting(containerEl)
.setName('Show indexing notices') new Setting(containerEl).setName('Behavior').setHeading()
.setDesc('Show a notice when indexing is done, usually at startup.')
.addToggle(toggle => // Index in real-time, desktop only
toggle.setValue(settings.showIndexingNotices).onChange(async v => { if (require('electron')) {
settings.showIndexingNotices = v new Setting(containerEl)
await saveSettings(this.plugin) .setName('Reindex in real-time')
}), .setDesc(
) "By default, notes a reindexed when Obsidian focus is lost. Enable this to reindex in real-time. May affect Obsidian's performances when editing large notes.",
)
.addToggle(toggle =>
toggle.setValue(settings.reindexInRealTime).onChange(async v => {
settings.reindexInRealTime = v
await saveSettings(this.plugin)
}),
)
}
else {
// No real time indexing on mobile
settings.reindexInRealTime = false
}
// Respect excluded files // Respect excluded files
new Setting(containerEl) new Setting(containerEl)
@@ -55,24 +68,37 @@ export class SettingsTab extends PluginSettingTab {
}), }),
) )
// Index in real-time, desktop only // #endregion Behavior
if (require('electron')) {
new Setting(containerEl) // #region User Interface
.setName('Reindex in real-time')
.setDesc( new Setting(containerEl).setName('User Interface').setHeading()
'By default, notes a reindexed when Obsidian focus is lost. Enable this to reindex in real-time. May affect performances.',
) // Show notices
.addToggle(toggle => new Setting(containerEl)
toggle.setValue(settings.reindexInRealTime).onChange(async v => { .setName('Show indexing notices')
settings.reindexInRealTime = v .setDesc('Show a notice when indexing is done, usually at startup.')
await saveSettings(this.plugin) .addToggle(toggle =>
}), toggle.setValue(settings.showIndexingNotices).onChange(async v => {
) settings.showIndexingNotices = v
} await saveSettings(this.plugin)
else { }),
// No real time indexing on mobile )
settings.reindexInRealTime = false
} // Display note names without the full path
new Setting(containerEl)
.setName('Hide full path in results list')
.setDesc(
'In the search results, only show the note name, without the full path.',
)
.addToggle(toggle =>
toggle.setValue(settings.showShortName).onChange(async v => {
settings.showShortName = v
await saveSettings(this.plugin)
}),
)
// #endregion User Interface
// #region Results Weighting // #region Results Weighting
@@ -135,10 +161,12 @@ export class SettingsTab extends PluginSettingTab {
} }
export const DEFAULT_SETTINGS: OmnisearchSettings = { export const DEFAULT_SETTINGS: OmnisearchSettings = {
showIndexingNotices: false,
respectExcluded: true, respectExcluded: true,
reindexInRealTime: false, reindexInRealTime: false,
showIndexingNotices: false,
showShortName: false,
weightBasename: 2, weightBasename: 2,
weightH1: 1.5, weightH1: 1.5,
weightH2: 1.3, weightH2: 1.3,