mirror of
https://github.com/zadam/trilium.git
synced 2026-03-10 02:13:38 +01:00
refactor: address gemini review
This commit is contained in:
parent
0ef7dd8fc2
commit
a6e0df70d7
@ -302,6 +302,9 @@ function initLabelValueAutocomplete({ $el, open, nameCallback, onValueChange }:
|
||||
isSelecting = false;
|
||||
|
||||
setTimeout(() => {
|
||||
// Preserve the legacy contract: several consumers still commit the
|
||||
// selected value from their existing Enter key handlers instead of
|
||||
// listening to the autocomplete selection event directly.
|
||||
inputEl.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "Enter",
|
||||
code: "Enter",
|
||||
|
||||
@ -111,8 +111,20 @@ function escapeHtml(text: string): string {
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
|
||||
function sanitizeHighlightedHtml(text: string, { allowBreaks = false }: { allowBreaks?: boolean } = {}): string {
|
||||
const sanitizedBreaks = allowBreaks
|
||||
? text.replace(/<br\b[^>]*\/?>/gi, "<br>")
|
||||
: text.replace(/<br\b[^>]*\/?>/gi, "");
|
||||
|
||||
return sanitizedBreaks
|
||||
.replace(/<b\b[^>]*>/gi, "<b>")
|
||||
.replace(/<\/b\s*>/gi, "</b>")
|
||||
.replace(/<\/?[^>]+>/g, "");
|
||||
}
|
||||
|
||||
function normalizeAttributeSnippet(snippet: string): string {
|
||||
return snippet.replace(/<br\s*\/?>/gi, " <span class=\"aa-core-separator\">·</span> ");
|
||||
return sanitizeHighlightedHtml(snippet, { allowBreaks: true })
|
||||
.replace(/<br\s*\/?>/gi, " <span class=\"aa-core-separator\">·</span> ");
|
||||
}
|
||||
|
||||
function getSuggestionIconClass(item: Suggestion): string {
|
||||
@ -135,7 +147,9 @@ function getSuggestionInputValue(item: Suggestion): string {
|
||||
|
||||
function renderCommandSuggestion(item: Suggestion): string {
|
||||
const iconClass = escapeHtml(item.icon || "bx bx-terminal");
|
||||
const titleHtml = item.highlightedNotePathTitle || escapeHtml(item.noteTitle || "");
|
||||
const titleHtml = item.highlightedNotePathTitle
|
||||
? sanitizeHighlightedHtml(item.highlightedNotePathTitle)
|
||||
: escapeHtml(item.noteTitle || "");
|
||||
const descriptionHtml = item.commandDescription ? `<div class="command-description">${escapeHtml(item.commandDescription)}</div>` : "";
|
||||
const shortcutHtml = item.commandShortcut ? `<kbd class="command-shortcut">${escapeHtml(item.commandShortcut)}</kbd>` : "";
|
||||
|
||||
@ -153,7 +167,9 @@ function renderCommandSuggestion(item: Suggestion): string {
|
||||
|
||||
function renderNoteSuggestion(item: Suggestion): string {
|
||||
const iconClass = escapeHtml(getSuggestionIconClass(item));
|
||||
const titleHtml = item.highlightedNotePathTitle || escapeHtml(item.noteTitle || item.notePathTitle || item.externalLink || "");
|
||||
const titleHtml = item.highlightedNotePathTitle
|
||||
? sanitizeHighlightedHtml(item.highlightedNotePathTitle)
|
||||
: escapeHtml(item.noteTitle || item.notePathTitle || item.externalLink || "");
|
||||
const shortcutHtml = item.action === "search-notes"
|
||||
? `<kbd class="aa-core-shortcut">Ctrl+Enter</kbd>`
|
||||
: "";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user