#109 - opt-out to keep line returns in excerpts
And removed the "show notice" setting
This commit is contained in:
@@ -103,11 +103,9 @@ class CacheManager {
|
|||||||
try {
|
try {
|
||||||
return MiniSearch.loadJS(cachedIndex.data, minisearchOptions)
|
return MiniSearch.loadJS(cachedIndex.data, minisearchOptions)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (settings.showIndexingNotices) {
|
|
||||||
new Notice(
|
new Notice(
|
||||||
'Omnisearch - Cache missing or invalid. Some freezes may occur while Omnisearch indexes your vault.'
|
'Omnisearch - Cache missing or invalid. Some freezes may occur while Omnisearch indexes your vault.'
|
||||||
)
|
)
|
||||||
}
|
|
||||||
console.error('Omnisearch - Error while loading Minisearch cache')
|
console.error('Omnisearch - Error while loading Minisearch cache')
|
||||||
console.error(e)
|
console.error(e)
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -296,7 +296,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 excerpt</span>
|
<span>to toggle excerpts</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>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const regexStripQuotes = /^"|"$|^'|'$/g
|
|||||||
export const chsRegex = /[\u4e00-\u9fa5]/
|
export const chsRegex = /[\u4e00-\u9fa5]/
|
||||||
|
|
||||||
export const excerptBefore = 100
|
export const excerptBefore = 100
|
||||||
export const excerptAfter = 180
|
export const excerptAfter = 300
|
||||||
|
|
||||||
export const highlightClass = 'suggestion-highlight omnisearch-highlight'
|
export const highlightClass = 'suggestion-highlight omnisearch-highlight'
|
||||||
|
|
||||||
|
|||||||
@@ -107,9 +107,7 @@ export function markNoteForReindex(note: TAbstractFile): void {
|
|||||||
|
|
||||||
export async function refreshIndex(): Promise<void> {
|
export async function refreshIndex(): Promise<void> {
|
||||||
if (notesToReindex.size > 0) {
|
if (notesToReindex.size > 0) {
|
||||||
if (settings.showIndexingNotices) {
|
console.info(`Omnisearch - Reindexing ${notesToReindex.size} notes`)
|
||||||
new Notice(`Omnisearch - Reindexing ${notesToReindex.size} notes`, 2000)
|
|
||||||
}
|
|
||||||
for (const note of notesToReindex) {
|
for (const note of notesToReindex) {
|
||||||
removeFromIndex(note.path)
|
removeFromIndex(note.path)
|
||||||
await addToIndexAndMemCache(note)
|
await addToIndexAndMemCache(note)
|
||||||
|
|||||||
170
src/settings.ts
170
src/settings.ts
@@ -27,14 +27,14 @@ export interface OmnisearchSettings extends WeightingSettings {
|
|||||||
PDFIndexing: boolean
|
PDFIndexing: boolean
|
||||||
/** Enable PDF indexing */
|
/** Enable PDF indexing */
|
||||||
imagesIndexing: boolean
|
imagesIndexing: boolean
|
||||||
/** Display Omnisearch popup notices over Obsidian */
|
|
||||||
showIndexingNotices: boolean
|
|
||||||
/** Activate the small 🔍 button on Obsidian's ribbon */
|
/** Activate the small 🔍 button on Obsidian's ribbon */
|
||||||
ribbonIcon: boolean
|
ribbonIcon: boolean
|
||||||
/** Display short filenames in search results, instead of the full path */
|
/** Display short filenames in search results, instead of the full path */
|
||||||
showShortName: boolean
|
showShortName: boolean
|
||||||
/** Display the small contextual excerpt in search results */
|
/** Display the small contextual excerpt in search results */
|
||||||
showExcerpt: boolean
|
showExcerpt: boolean
|
||||||
|
/** Render line returns with <br> in excerpts */
|
||||||
|
renderLineReturnInExcerpts: boolean
|
||||||
/** Enable a "create note" button in the Vault Search modal */
|
/** Enable a "create note" button in the Vault Search modal */
|
||||||
showCreateButton: boolean
|
showCreateButton: boolean
|
||||||
/** Re-execute the last query when opening Omnisearch */
|
/** Re-execute the last query when opening Omnisearch */
|
||||||
@@ -77,6 +77,74 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
<a href='https://ko-fi.com/B0B6LQ2C' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
<a href='https://ko-fi.com/B0B6LQ2C' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
//#region Indexing
|
||||||
|
|
||||||
|
new Setting(containerEl).setName('Indexing').setHeading()
|
||||||
|
|
||||||
|
// PDF Indexing
|
||||||
|
const indexPDFsDesc = new DocumentFragment()
|
||||||
|
indexPDFsDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `Omnisearch will include PDFs in search results.
|
||||||
|
<ul>
|
||||||
|
<li>⚠️ Each PDF can take anywhere from a few seconds to 2 minutes to be processed.</li>
|
||||||
|
<li>⚠️ Texts extracted from PDFs may contain errors such as missing spaces, or spaces in the middle of words.</li>
|
||||||
|
<li>⚠️ Some PDFs can't be processed correctly and will return an empty text.</li>
|
||||||
|
<li>This feature is currently a work-in-progress, please report issues that you might experience.</li>
|
||||||
|
</ul>
|
||||||
|
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
||||||
|
})
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('BETA - PDF Indexing')
|
||||||
|
.setDesc(indexPDFsDesc)
|
||||||
|
.addToggle(toggle =>
|
||||||
|
toggle.setValue(settings.PDFIndexing).onChange(async v => {
|
||||||
|
settings.PDFIndexing = v
|
||||||
|
await saveSettings(this.plugin)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
// Images Indexing
|
||||||
|
const indexImagesDesc = new DocumentFragment()
|
||||||
|
indexImagesDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `Omnisearch will use <a href="https://en.wikipedia.org/wiki/Tesseract_(software)">Tesseract</a> to index images from their text.
|
||||||
|
<ul>
|
||||||
|
<li>Only English is supported at the moment.</li>
|
||||||
|
<li>Not all images can be correctly read by the OCR, this feature works best with scanned documents.</li>
|
||||||
|
</ul>
|
||||||
|
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
||||||
|
})
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('BETA - Images Indexing')
|
||||||
|
.setDesc(indexImagesDesc)
|
||||||
|
.addToggle(toggle =>
|
||||||
|
toggle.setValue(settings.imagesIndexing).onChange(async v => {
|
||||||
|
settings.imagesIndexing = v
|
||||||
|
await saveSettings(this.plugin)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
// Additional files to index
|
||||||
|
const indexedFileTypesDesc = new DocumentFragment()
|
||||||
|
indexedFileTypesDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `In addition to standard <code>md</code> files, Omnisearch can also index other plain text files.<br/>
|
||||||
|
Add extensions separated by a space, without the dot. Example: "<code>txt org</code>".<br />
|
||||||
|
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
||||||
|
})
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Additional files to index')
|
||||||
|
.setDesc(indexedFileTypesDesc)
|
||||||
|
.addText(component => {
|
||||||
|
component
|
||||||
|
.setValue(settings.indexedFileTypes.join(' '))
|
||||||
|
.setPlaceholder('Example: txt org')
|
||||||
|
.onChange(async v => {
|
||||||
|
settings.indexedFileTypes = v.split(' ')
|
||||||
|
await saveSettings(this.plugin)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
//#endregion Indexing
|
||||||
|
|
||||||
// #region Behavior
|
// #region Behavior
|
||||||
|
|
||||||
new Setting(containerEl).setName('Behavior').setHeading()
|
new Setting(containerEl).setName('Behavior').setHeading()
|
||||||
@@ -112,27 +180,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Additional files to index
|
// Simpler search
|
||||||
const indexedFileTypesDesc = new DocumentFragment()
|
|
||||||
indexedFileTypesDesc.createSpan({}, span => {
|
|
||||||
span.innerHTML = `In addition to standard <code>md</code> files, Omnisearch can also index other plain text files.<br/>
|
|
||||||
Add extensions separated by a space, without the dot. Example: "<code>txt org</code>".<br />
|
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
|
||||||
})
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('Additional files to index')
|
|
||||||
.setDesc(indexedFileTypesDesc)
|
|
||||||
.addText(component => {
|
|
||||||
component
|
|
||||||
.setValue(settings.indexedFileTypes.join(' '))
|
|
||||||
.setPlaceholder('Example: txt org')
|
|
||||||
.onChange(async v => {
|
|
||||||
settings.indexedFileTypes = v.split(' ')
|
|
||||||
await saveSettings(this.plugin)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// Ignore diacritics
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Simpler search')
|
.setName('Simpler search')
|
||||||
.setDesc(
|
.setDesc(
|
||||||
@@ -146,48 +194,6 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// PDF Indexing
|
|
||||||
const indexPDFsDesc = new DocumentFragment()
|
|
||||||
indexPDFsDesc.createSpan({}, span => {
|
|
||||||
span.innerHTML = `Omnisearch will include PDFs in search results.
|
|
||||||
<ul>
|
|
||||||
<li>⚠️ Each PDF can take anywhere from a few seconds to 2 minutes to be processed.</li>
|
|
||||||
<li>⚠️ Texts extracted from PDFs may contain errors such as missing spaces, or spaces in the middle of words.</li>
|
|
||||||
<li>⚠️ Some PDFs can't be processed correctly and will return an empty text.</li>
|
|
||||||
<li>This feature is currently a work-in-progress, please report issues that you might experience.</li>
|
|
||||||
</ul>
|
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
|
||||||
})
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('BETA - PDF Indexing')
|
|
||||||
.setDesc(indexPDFsDesc)
|
|
||||||
.addToggle(toggle =>
|
|
||||||
toggle.setValue(settings.PDFIndexing).onChange(async v => {
|
|
||||||
settings.PDFIndexing = v
|
|
||||||
await saveSettings(this.plugin)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
// PDF Indexing
|
|
||||||
const indexImagesDesc = new DocumentFragment()
|
|
||||||
indexImagesDesc.createSpan({}, span => {
|
|
||||||
span.innerHTML = `Omnisearch will use <a href="https://en.wikipedia.org/wiki/Tesseract_(software)">Tesseract</a> to index images from their text.
|
|
||||||
<ul>
|
|
||||||
<li>Only English is supported at the moment.</li>
|
|
||||||
<li>Not all images can be correctly read by the OCR, this feature works best with scanned documents.</li>
|
|
||||||
</ul>
|
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
|
||||||
})
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('BETA - Images Indexing')
|
|
||||||
.setDesc(indexImagesDesc)
|
|
||||||
.addToggle(toggle =>
|
|
||||||
toggle.setValue(settings.imagesIndexing).onChange(async v => {
|
|
||||||
settings.imagesIndexing = v
|
|
||||||
await saveSettings(this.plugin)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
// #endregion Behavior
|
// #endregion Behavior
|
||||||
|
|
||||||
// #region User Interface
|
// #region User Interface
|
||||||
@@ -212,9 +218,9 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
|
|
||||||
// Show context excerpt
|
// Show context excerpt
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Show excerpt')
|
.setName('Show excerpts')
|
||||||
.setDesc(
|
.setDesc(
|
||||||
'Shows the part of the note that matches the search. Disable this to only show filenames in results.'
|
'Shows the contextual part of the note that matches the search. Disable this to only show filenames in results.'
|
||||||
)
|
)
|
||||||
.addToggle(toggle =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.showExcerpt).onChange(async v => {
|
toggle.setValue(settings.showExcerpt).onChange(async v => {
|
||||||
@@ -222,10 +228,23 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Show context excerpt
|
// Keep line returns in excerpts
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Render line return in excerpts')
|
||||||
|
.setDesc('Activate this option render line returns in result excerpts.')
|
||||||
|
.addToggle(toggle =>
|
||||||
|
toggle
|
||||||
|
.setValue(settings.renderLineReturnInExcerpts)
|
||||||
|
.onChange(async v => {
|
||||||
|
settings.renderLineReturnInExcerpts = v
|
||||||
|
await saveSettings(this.plugin)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
// Show previous query results
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Show previous query results')
|
.setName('Show previous query results')
|
||||||
.setDesc('Re-executes the previous query when opening Omnisearch')
|
.setDesc('Re-executes the previous query when opening Omnisearch.')
|
||||||
.addToggle(toggle =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.showPreviousQueryResults).onChange(async v => {
|
toggle.setValue(settings.showPreviousQueryResults).onChange(async v => {
|
||||||
settings.showPreviousQueryResults = v
|
settings.showPreviousQueryResults = v
|
||||||
@@ -249,17 +268,6 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Show notices
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('Show indexing notices')
|
|
||||||
.setDesc('Shows a notice when indexing is done, usually at startup.')
|
|
||||||
.addToggle(toggle =>
|
|
||||||
toggle.setValue(settings.showIndexingNotices).onChange(async v => {
|
|
||||||
settings.showIndexingNotices = v
|
|
||||||
await saveSettings(this.plugin)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
// Display note names without the full path
|
// Display note names without the full path
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Hide full path in results list')
|
.setName('Hide full path in results list')
|
||||||
@@ -341,10 +349,10 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
|||||||
PDFIndexing: false,
|
PDFIndexing: false,
|
||||||
imagesIndexing: false,
|
imagesIndexing: false,
|
||||||
|
|
||||||
showIndexingNotices: false,
|
|
||||||
showShortName: false,
|
showShortName: false,
|
||||||
ribbonIcon: true,
|
ribbonIcon: true,
|
||||||
showExcerpt: true,
|
showExcerpt: true,
|
||||||
|
renderLineReturnInExcerpts: true,
|
||||||
showCreateButton: false,
|
showCreateButton: false,
|
||||||
showPreviousQueryResults: true,
|
showPreviousQueryResults: true,
|
||||||
simpleSearch: false,
|
simpleSearch: false,
|
||||||
|
|||||||
@@ -92,15 +92,38 @@ export function loopIndex(index: number, nbItems: number): number {
|
|||||||
export function makeExcerpt(content: string, offset: number): string {
|
export function makeExcerpt(content: string, offset: number): string {
|
||||||
try {
|
try {
|
||||||
const pos = offset ?? -1
|
const pos = offset ?? -1
|
||||||
if (pos > -1) {
|
|
||||||
const from = Math.max(0, pos - excerptBefore)
|
const from = Math.max(0, pos - excerptBefore)
|
||||||
const to = Math.min(content.length, pos + excerptAfter)
|
const to = Math.min(content.length, pos + excerptAfter)
|
||||||
|
if (pos > -1) {
|
||||||
content =
|
content =
|
||||||
(from > 0 ? '…' : '') +
|
(from > 0 ? '…' : '') +
|
||||||
content.slice(from, to).trim() +
|
content.slice(from, to).trim() +
|
||||||
(to < content.length - 1 ? '…' : '')
|
(to < content.length - 1 ? '…' : '')
|
||||||
|
} else {
|
||||||
|
content = content.slice(0, excerptAfter)
|
||||||
}
|
}
|
||||||
return escapeHTML(content)
|
if (settings.renderLineReturnInExcerpts) {
|
||||||
|
const lineReturn = new RegExp(/(?:\r\n|\r|\n)/g)
|
||||||
|
// Remove multiple line returns
|
||||||
|
content = content
|
||||||
|
.split(lineReturn)
|
||||||
|
.filter(l => l)
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
|
const last = content.lastIndexOf('\n', pos - from)
|
||||||
|
|
||||||
|
if (last > 0) {
|
||||||
|
content = content.slice(last)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content = escapeHTML(content)
|
||||||
|
|
||||||
|
if (settings.renderLineReturnInExcerpts) {
|
||||||
|
content = content.trim().replaceAll('\n', '<br>')
|
||||||
|
}
|
||||||
|
|
||||||
|
return content
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
new Notice(
|
new Notice(
|
||||||
'Omnisearch - Error while creating excerpt, see developer console'
|
'Omnisearch - Error while creating excerpt, see developer console'
|
||||||
|
|||||||
Reference in New Issue
Block a user