Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
style(autocomplete): set the search rows apart from the notes
Elian Doranb04ec8bed5d8
diff --git a/apps/client/src/stylesheets/theme-next/base.css b/apps/client/src/stylesheets/theme-next/base.cssindex 8e84a3454f..8eafb53423 100644--- a/apps/client/src/stylesheets/theme-next/base.css+++ b/apps/client/src/stylesheets/theme-next/base.css@@ -332,8 +332,8 @@ html body .dropdown-item[disabled] {position: absolute;content: "";top: -1px;- inset-inline-start: calc(0px - var(--menu-padding-size));- inset-inline-end: calc(0px - var(--menu-padding-size));+ inset-inline-start: calc(0px - var(--padding, var(--menu-padding-size)));+ inset-inline-end: calc(0px - var(--padding, var(--menu-padding-size)));border-top: 1px solid var(--menu-item-delimiter-color);}diff --git a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsxindex cdfaebfe30..24b8fb3c77 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx@@ -478,6 +478,9 @@ describe("NoteAutocomplete's suggestion list", () => {expect(allRows().at(-1)).toBe(row);expect(row?.querySelector("kbd")?.textContent).toBe("Shift+Enter");expect(row?.querySelector(".tn-icon")?.className).toBe("bx bx-search tn-icon");+ // Set apart from the notes above it.+ expect(row?.previousElementSibling?.className).toBe("dropdown-divider");+ expect(document.querySelectorAll(".note-autocomplete-menu .dropdown-divider")).toHaveLength(1);// The first note keeps the highlight, though the row's title is the query itself.expect(rows()[0].classList.contains("tn-menu-active")).toBe(true);@@ -588,6 +591,17 @@ describe("NoteAutocomplete's suggestion list", () => {});});+ it("sets both search rows apart from the notes with one line", async () => {+ getNoteSuggestions.mockResolvedValue([ ...notes, searchRow ]);+ const input = await mount();+ await type(input, "al");++ const dividers = [ ...document.querySelectorAll(".note-autocomplete-menu .dropdown-divider") ];+ expect(dividers).toHaveLength(1);+ expect(dividers[0].previousElementSibling).toBe(rows()[1]);+ expect(dividers[0].nextElementSibling).toBe(fullTextRow());+ });+it("runs a search from its row, with its shortcut shown, leaving the field", async () => {const onChange = vi.fn();getNoteSuggestions.mockResolvedValue([ searchRow ]);@@ -595,6 +609,8 @@ describe("NoteAutocomplete's suggestion list", () => {await type(input, "al");expect(rows()[0].querySelector("kbd")?.textContent).toBe("Ctrl+Enter");+ // No notes above the search rows to set them apart from.+ expect(document.querySelector(".note-autocomplete-menu .dropdown-divider")).toBeNull();// Past the full-text search row ahead of it.await press(input, "ArrowDown");await press(input, "Enter");diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsxindex 806e372f61..f463b72e73 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx@@ -3,7 +3,7 @@ import "./NoteAutocomplete.css";import clsx from "clsx";import { type RefObject, render } from "preact";-import { createPortal, type CSSProperties } from "preact/compat";+import { createPortal, type CSSProperties, Fragment } from "preact/compat";import { type MutableRef, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";import appContext from "../../components/app_context";@@ -12,6 +12,7 @@ import { t } from "../../services/i18n";import { createSearchScheduler, createNoteFromSuggestion, getCommandSuggestions, getNoteSuggestions, type Options, type Suggestion } from "../../services/note_autocomplete";import { escapeHtml } from "../../services/utils";import { useAutocomplete } from "./FormAutocomplete";+import { FormDropdownDivider } from "./FormList";import { useSyncedRef } from "./hooks";import Icon from "./Icon";import Popup from "./Popup";@@ -387,17 +388,19 @@ function NoteSuggestionMenu({ autocomplete, searchingFor }: {</li>)}{searchingFor === undefined && autocomplete.items.map((suggestion, index) => (- <li- key={`${suggestion.action ?? ""}:${suggestion.notePath ?? suggestion.commandId ?? index}`}- id={autocomplete.itemId(index)}- className={clsx("dropdown-item", index === autocomplete.activeIndex && "tn-menu-active")}- role="option"- aria-selected={index === autocomplete.activeIndex}- onMouseEnter={() => autocomplete.setActiveIndex(index)}- onClick={() => autocomplete.pick(suggestion)}- >- <NoteSuggestionMenuItem suggestion={suggestion} />- </li>+ <Fragment key={`${suggestion.action ?? ""}:${suggestion.notePath ?? suggestion.commandId ?? index}`}>+ {index > 0 && isSearchRow(suggestion) && !isSearchRow(autocomplete.items[index - 1]) && <FormDropdownDivider />}+ <li+ id={autocomplete.itemId(index)}+ className={clsx("dropdown-item", index === autocomplete.activeIndex && "tn-menu-active")}+ role="option"+ aria-selected={index === autocomplete.activeIndex}+ onMouseEnter={() => autocomplete.setActiveIndex(index)}+ onClick={() => autocomplete.pick(suggestion)}+ >+ <NoteSuggestionMenuItem suggestion={suggestion} />+ </li>+ </Fragment>))}</menu>);@@ -470,6 +473,11 @@ function NoteSuggestion({ suggestion }: { suggestion: Suggestion }) {);}+/** The rows that run a search for the query, which the menu sets apart from the notes above them. */+function isSearchRow(suggestion: Suggestion) {+ return suggestion.action === "full-text-search" || suggestion.action === "search-notes";+}+function suggestionIcon(suggestion: Suggestion) {switch (suggestion.action) {case "search-notes": return "bx bx-search";