Highlighting rework, should help with #304

This commit is contained in:
Simon Cambier
2024-03-26 21:32:03 +01:00
parent f77ff3ec2f
commit 484e961a7e
6 changed files with 32 additions and 31 deletions

View File

@@ -1,8 +1,5 @@
<script lang="ts">
import {
makeExcerpt,
highlightText,
} from 'src/tools/text-processing'
import { makeExcerpt, highlightText } from 'src/tools/text-processing'
import type { ResultNote } from '../globals'
import ResultItemContainer from './ResultItemContainer.svelte'
import { cloneDeep } from 'lodash-es'
@@ -13,10 +10,7 @@
export let selected = false
$: cleanedContent = makeExcerpt(note?.content ?? '', offset)
$: matchesExcerpt = cloneDeep(note.matches).map(m => {
m.offset = m.offset - cleanedContent.offset
return m
})
$: matchesExcerpt = cloneDeep(note.matches)
</script>
<ResultItemContainer
@@ -26,6 +20,6 @@
on:click
on:auxclick>
<div class="omnisearch-result__body">
{@html highlightText(cleanedContent.content, matchesExcerpt)}
{@html highlightText(cleanedContent, matchesExcerpt)}
</div>
</ResultItemContainer>

View File

@@ -40,10 +40,6 @@
$: reg = stringsToRegex(note.foundWords)
$: matchesTitle = getMatches(title, reg)
$: matchesNotePath = getMatches(notePath, reg)
$: matchesExcerpt = cloneDeep(note.matches).map(m => {
m.offset = m.offset - cleanedContent.offset
return m
})
$: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
$: glyph = false //cacheManager.getLiveDocument(note.path)?.doesNotExist
$: {
@@ -102,7 +98,7 @@
<div style="display: flex; flex-direction: row;">
{#if $showExcerpt}
<div class="omnisearch-result__body">
{@html highlightText(cleanedContent.content, matchesExcerpt)}
{@html highlightText(cleanedContent, note.matches)}
</div>
{/if}