mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 02:02:29 +08:00
feat(jump-to-note): ignore ~internalLink (closes #713)
This commit is contained in:
parent
9494362fb0
commit
43567525e3
@ -9,6 +9,8 @@ class SearchContext {
|
||||
includeArchivedNotes: boolean;
|
||||
includeHiddenNotes: boolean;
|
||||
ignoreHoistedNote: boolean;
|
||||
/** Whether to ignore certain attributes from the search such as ~internalLink. */
|
||||
ignoreInternalAttributes: boolean;
|
||||
ancestorNoteId?: string;
|
||||
ancestorDepth?: string;
|
||||
orderBy?: string;
|
||||
@ -28,6 +30,7 @@ class SearchContext {
|
||||
this.includeArchivedNotes = !!params.includeArchivedNotes;
|
||||
this.includeHiddenNotes = !!params.includeHiddenNotes;
|
||||
this.ignoreHoistedNote = !!params.ignoreHoistedNote;
|
||||
this.ignoreInternalAttributes = !!params.ignoreInternalAttributes;
|
||||
this.ancestorNoteId = params.ancestorNoteId;
|
||||
|
||||
if (!this.ancestorNoteId && !this.ignoreHoistedNote) {
|
||||
|
@ -346,6 +346,7 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) {
|
||||
includeArchivedNotes: false,
|
||||
includeHiddenNotes: true,
|
||||
fuzzyAttributeSearch: true,
|
||||
ignoreInternalAttributes: true,
|
||||
ancestorNoteId: hoistedNoteService.isHoistedInHiddenSubtree()
|
||||
? 'root'
|
||||
: hoistedNoteService.getHoistedNoteId()
|
||||
@ -355,7 +356,7 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) {
|
||||
|
||||
const trimmed = allSearchResults.slice(0, 200);
|
||||
|
||||
highlightSearchResults(trimmed, searchContext.highlightedTokens);
|
||||
highlightSearchResults(trimmed, searchContext.highlightedTokens, searchContext.ignoreInternalAttributes);
|
||||
|
||||
return trimmed.map(result => {
|
||||
return {
|
||||
@ -367,7 +368,10 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) {
|
||||
});
|
||||
}
|
||||
|
||||
function highlightSearchResults(searchResults: SearchResult[], highlightedTokens: string[]) {
|
||||
/**
|
||||
* @param ignoreInternalAttributes whether to ignore certain attributes from the search such as ~internalLink.
|
||||
*/
|
||||
function highlightSearchResults(searchResults: SearchResult[], highlightedTokens: string[], ignoreInternalAttributes = false) {
|
||||
highlightedTokens = Array.from(new Set(highlightedTokens));
|
||||
|
||||
// we remove < signs because they can cause trouble in matching and overwriting existing highlighted chunks
|
||||
@ -395,6 +399,10 @@ function highlightSearchResults(searchResults: SearchResult[], highlightedTokens
|
||||
}
|
||||
|
||||
for (const attr of note.getAttributes()) {
|
||||
if (attr.type === "relation" && attr.name === "internalLink" && ignoreInternalAttributes) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (highlightedTokens.find(token => utils.normalize(attr.name).includes(token)
|
||||
|| utils.normalize(attr.value).includes(token))) {
|
||||
|
||||
|
@ -12,6 +12,8 @@ export interface SearchParams {
|
||||
includeArchivedNotes?: boolean;
|
||||
includeHiddenNotes?: boolean;
|
||||
ignoreHoistedNote?: boolean;
|
||||
/** Whether to ignore certain attributes from the search such as ~internalLink. */
|
||||
ignoreInternalAttributes?: boolean;
|
||||
ancestorNoteId?: string;
|
||||
ancestorDepth?: string;
|
||||
orderBy?: string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user