mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
feat: update "jump to" dialog to use better search results, and separate renderer for "quick search" and "jump to"
- Add shared search result renderer for consistent snippet display - Display content and attribute snippets in Quick Search and Jump To dialog - Fix crash when encountering orphaned notes without paths - Add minimal CSS for snippet highlighting This provides a better search experience by showing snippets of matching content directly in search results, helping users identify the right note without opening it. fix: Always show content snippets in search results for better context - Modified extractContentSnippet to always return a snippet from the beginning of the note when search tokens don't match the content - Modified extractAttributeSnippet to show first few attributes when no match is found - This ensures Jump To dialog and Quick Search always provide context via content snippets, even when searching by tags/attributes - Helps users identify the right note regardless of what matched (content, tags, or attributes) asdf
This commit is contained in:
67
apps/client/src/services/quick_search_renderer.ts
Normal file
67
apps/client/src/services/quick_search_renderer.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Quick Search specific result renderer
|
||||
*
|
||||
* This module provides HTML rendering functionality specifically for the Quick Search widget.
|
||||
* The Jump To dialog (note_autocomplete) intentionally has its own inline rendering logic
|
||||
* with different styling and layout requirements.
|
||||
*
|
||||
* SECURITY NOTE: HTML Snippet Handling
|
||||
* The highlighted snippet fields (highlightedContentSnippet, highlightedAttributeSnippet) contain
|
||||
* pre-sanitized HTML from the server. The server-side processing:
|
||||
* 1. Escapes all HTML using the escape-html library
|
||||
* 2. Adds safe HTML tags for display: <b> for search term highlighting, <br> for line breaks
|
||||
* 3. See apps/server/src/services/search/services/search.ts for implementation
|
||||
*
|
||||
* This means the HTML snippets can be safely inserted without additional escaping on the client side.
|
||||
*/
|
||||
|
||||
import type { Suggestion } from "./note_autocomplete.js";
|
||||
|
||||
/**
|
||||
* Creates HTML for a Quick Search result item
|
||||
*
|
||||
* @param result - The search result item to render
|
||||
* @returns HTML string formatted for Quick Search widget display
|
||||
*/
|
||||
export function createSearchResultHtml(result: Suggestion): string {
|
||||
// Handle command action
|
||||
if (result.action === "command") {
|
||||
let html = `<div class="command-suggestion">`;
|
||||
html += `<span class="command-icon ${result.icon || "bx bx-terminal"}"></span>`;
|
||||
html += `<div class="command-content">`;
|
||||
html += `<div class="command-name">${result.highlightedNotePathTitle || ''}</div>`;
|
||||
if (result.commandDescription) {
|
||||
html += `<div class="command-description">${result.commandDescription}</div>`;
|
||||
}
|
||||
html += `</div>`;
|
||||
if (result.commandShortcut) {
|
||||
html += `<kbd class="command-shortcut">${result.commandShortcut}</kbd>`;
|
||||
}
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
|
||||
// Default: render as note result with snippets
|
||||
// Wrap everything in a flex column container
|
||||
let itemHtml = `<div style="display: flex; flex-direction: column; gap: 2px;">`;
|
||||
|
||||
// Title row with icon
|
||||
itemHtml += `<div style="display: flex; align-items: center; gap: 6px;">`;
|
||||
itemHtml += `<span class="${result.icon || 'bx bx-note'}" style="flex-shrink: 0;"></span>`;
|
||||
itemHtml += `<span class="search-result-title" style="flex: 1;">${result.highlightedNotePathTitle || result.notePathTitle || ''}</span>`;
|
||||
itemHtml += `</div>`;
|
||||
|
||||
// Add attribute snippet if available
|
||||
if (result.highlightedAttributeSnippet && result.highlightedAttributeSnippet.trim()) {
|
||||
itemHtml += `<div class="search-result-attributes" style="margin-left: 20px;">${result.highlightedAttributeSnippet}</div>`;
|
||||
}
|
||||
|
||||
// Add content snippet if available
|
||||
if (result.highlightedContentSnippet && result.highlightedContentSnippet.trim()) {
|
||||
itemHtml += `<div class="search-result-content" style="margin-left: 20px;">${result.highlightedContentSnippet}</div>`;
|
||||
}
|
||||
|
||||
itemHtml += `</div>`;
|
||||
|
||||
return itemHtml;
|
||||
}
|
||||
Reference in New Issue
Block a user