mirror of
https://github.com/zadam/trilium.git
synced 2024-09-29 03:55:59 +08:00
fixed messed up highlighting when searching e.g. "a"
This commit is contained in:
parent
c45f590e9f
commit
d163289003
|
@ -123,6 +123,7 @@ function highlightSearchResults(searchResults, highlightedTokens) {
|
|||
// we remove < signs because they can cause trouble in matching and overwriting existing highlighted chunks
|
||||
// which would make the resulting HTML string invalid.
|
||||
// { and } are used for marking <b> and </b> tag (to avoid matches on single 'b' character)
|
||||
// < and > are used for marking <small> and </small>
|
||||
highlightedTokens = highlightedTokens.map(token => token.replace('/[<\{\}]/g', ''));
|
||||
|
||||
// sort by the longest so we first highlight longest matches
|
||||
|
@ -131,19 +132,19 @@ function highlightSearchResults(searchResults, highlightedTokens) {
|
|||
for (const result of searchResults) {
|
||||
const note = noteCache.notes[result.noteId];
|
||||
|
||||
result.highlightedNotePathTitle = result.notePathTitle;
|
||||
result.highlightedNotePathTitle = result.notePathTitle.replace('/[<\{\}]/g', '');
|
||||
|
||||
if (highlightedTokens.find(token => note.type.includes(token))) {
|
||||
result.highlightedNotePathTitle += ` <small>type: ${note.type}</small>`;
|
||||
result.highlightedNotePathTitle += ` <type: ${note.type}>`;
|
||||
}
|
||||
|
||||
if (highlightedTokens.find(token => note.mime.includes(token))) {
|
||||
result.highlightedNotePathTitle += ` <small>mime: ${note.mime}</small>`;
|
||||
result.highlightedNotePathTitle += ` <mime: ${note.mime}>`;
|
||||
}
|
||||
|
||||
for (const attr of note.attributes) {
|
||||
if (highlightedTokens.find(token => attr.name.includes(token) || attr.value.includes(token))) {
|
||||
result.highlightedNotePathTitle += ` <small>${formatAttribute(attr)}</small>`;
|
||||
result.highlightedNotePathTitle += ` <${formatAttribute(attr)}>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +159,8 @@ function highlightSearchResults(searchResults, highlightedTokens) {
|
|||
|
||||
for (const result of searchResults) {
|
||||
result.highlightedNotePathTitle = result.highlightedNotePathTitle
|
||||
.replace(/</g, "<small>")
|
||||
.replace(/>/g, "</small>")
|
||||
.replace(/{/g, "<b>")
|
||||
.replace(/}/g, "</b>");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue