Skip to content

Build your personal knowledge base with Trilium Notes

refactor(quick_search): pin "Show in full search" below the results

Elian Doran0ae2ce1447fc
diff --git a/apps/client/src/stylesheets/theme-next/shell.css b/apps/client/src/stylesheets/theme-next/shell.css
index b0565557c4..8958f195df 100644
--- a/apps/client/src/stylesheets/theme-next/shell.css
+++ b/apps/client/src/stylesheets/theme-next/shell.css
@@ -593,10 +593,6 @@ div.bookmark-folder-widget .note-link .tn-icon {
color: var(--quick-search-result-highlight-color);
font-weight: 600;
}
-
- .dropdown-divider {
- margin: 8px 0;
- }
}
/*
diff --git a/apps/client/src/widgets/quick_search.css b/apps/client/src/widgets/quick_search.css
index f8ab48cd1d..a8f8fd4aa5 100644
--- a/apps/client/src/widgets/quick_search.css
+++ b/apps/client/src/widgets/quick_search.css
@@ -9,7 +9,6 @@
var(--left-pane-item-action-button-color, var(--main-text-color));
display: flex;
- /* Around the box, and still part of the widget. */
padding: 8px;
/* `.component`, which `BasicWidget` adds, sets `contain: size` and would collapse the box. */
@@ -79,7 +78,7 @@
color: var(--quick-search-focus-color, var(--main-text-color));
}
- /* `!important` outranks Bootstrap's `.btn` state rules (`:hover`, `:active`, `.show`). */
+ /* `!important` outranks Bootstrap's `.btn` state rules (`:hover`, `:active`, `.active`). */
.search-button {
display: flex;
align-items: center;
@@ -135,19 +134,27 @@
&.show {
display: flex;
flex-direction: column;
- padding-block: 0 !important;
+ padding: 0 !important;
}
.quick-search-results {
flex: 1 1 auto;
min-height: 0;
- padding-block: var(--menu-padding-size, .5rem);
+ padding: var(--menu-padding-size, .5rem 0);
overflow-y: auto;
overflow-x: hidden;
}
.quick-search-footer {
+ display: flex;
flex: 0 0 auto;
+ justify-content: flex-end;
+ padding: var(--menu-padding-size, .5rem);
+ border-top: 1px solid var(--dropdown-border-color, var(--main-border-color));
+
+ kbd {
+ padding: .1875rem .375rem;
+ }
}
.dropdown-item {
@@ -227,10 +234,6 @@
}
}
- .dropdown-divider {
- margin: 0;
- }
-
.bx-loader {
margin-inline-end: 4px;
}
diff --git a/apps/client/src/widgets/quick_search.spec.tsx b/apps/client/src/widgets/quick_search.spec.tsx
index d8b7c01b51..51d42c944e 100644
--- a/apps/client/src/widgets/quick_search.spec.tsx
+++ b/apps/client/src/widgets/quick_search.spec.tsx
@@ -4,6 +4,7 @@ import { options, type VNode } from "preact";
import { act } from "preact/test-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
+import appContext from "../components/app_context";
import Component from "../components/component";
import { calculateHash } from "../services/link";
import server from "../services/server";
@@ -212,6 +213,36 @@ describe("QuickSearch", () => {
expect(editor.hasFocus).toBe(true);
});
+ it("hands the query to the full search from a footer below the results, and on Ctrl+Enter", async () => {
+ vi.spyOn(server, "get").mockResolvedValue(response(30, []));
+ const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockResolvedValue(undefined);
+ const { editor } = await mount();
+
+ typeQuery(editor, " #book AND tolkien ");
+ pressEnter(editor);
+ await waitForResults(30);
+
+ // Pinned below the scroller rather than at the end of the list, so it is always in reach.
+ const footer = menu()?.lastElementChild;
+ expect(footer?.classList.contains("quick-search-footer")).toBe(true);
+ const button = footer?.querySelector<HTMLButtonElement>("button");
+ if (!button) throw new Error("The footer has no button.");
+
+ await act(async () => button.click());
+ expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "#book AND tolkien" });
+ await vi.waitFor(() => expect(menu()).toBeNull());
+
+ // From the field too, with the results closed.
+ triggerCommand.mockClear();
+ act(() => {
+ editor.contentDOM.dispatchEvent(new KeyboardEvent("keydown", {
+ key: "Enter", ctrlKey: true, bubbles: true, cancelable: true
+ }));
+ });
+ expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "#book AND tolkien" });
+ expect(menu()).toBeNull();
+ });
+
it("leaves the open results alone while the query is typed", async () => {
vi.spyOn(server, "get").mockResolvedValue(response(15, []));
const { editor } = await mount();
diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsx
index 80bbd9605b..be1d642449 100644
--- a/apps/client/src/widgets/quick_search.tsx
+++ b/apps/client/src/widgets/quick_search.tsx
@@ -6,10 +6,12 @@ import clsx from "clsx";
import type { RefObject } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
+import appContext from "../components/app_context";
import { t } from "../services/i18n";
import { calculateHash, type ViewScope } from "../services/link";
import server from "../services/server";
import ActionButton from "./react/ActionButton";
+import Button from "./react/Button";
import { focusListItem } from "./react/FormList";
import { useTriliumEvent } from "./react/hooks";
import Icon from "./react/Icon";
@@ -60,6 +62,11 @@ export default function QuickSearch() {
});
}
+ function showInFullSearch() {
+ close();
+ void appContext.triggerCommand("searchNotes", { searchString: searchStringRef.current.trim() });
+ }
+
function close() {
// Focus on a result goes back to the field, rather than to the page's body.
if (popupRef.current?.contains(document.activeElement)) editorRef.current?.focus();
@@ -68,7 +75,17 @@ export default function QuickSearch() {
return (
<div className={clsx("quick-search", hasQuery && "has-query")}>
- <div ref={boxRef} className="quick-search-box">
+ <div
+ ref={boxRef}
+ className="quick-search-box"
+ // Captured, so the field never takes the Enter for its own search.
+ onKeyDownCapture={(e) => {
+ if (e.key !== "Enter" || !e.ctrlKey) return;
+ e.preventDefault();
+ e.stopPropagation();
+ showInFullSearch();
+ }}
+ >
<ActionButton
className="search-button"
icon="bx bx-search"
@@ -110,6 +127,14 @@ export default function QuickSearch() {
<div className="quick-search-results">
<QuickSearchResults searchState={searchState} onOpenResult={close} />
</div>
+ <div className="quick-search-footer">
+ <Button
+ text={t("quick-search.show-in-full-search")}
+ keyboardShortcut="Ctrl+Enter"
+ size="small"
+ onClick={showInFullSearch}
+ />
+ </div>
</Popup>
)}
</div>
diff --git a/apps/client/src/widgets/quick_search_old.spec.ts b/apps/client/src/widgets/quick_search_old.spec.ts
deleted file mode 100644
index 9118f38189..0000000000
--- a/apps/client/src/widgets/quick_search_old.spec.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-
-import appContext from "../components/app_context.js";
-import server from "../services/server.js";
-import QuickSearchWidget from "./quick_search_old.js";
-
-describe("QuickSearchWidget", () => {
- beforeEach(() => {
- vi.restoreAllMocks();
- });
-
- afterEach(() => {
- document.body.innerHTML = "";
- });
-
- it("searches for the query and hands it to the full search", async () => {
- const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockResolvedValue(undefined);
- const widget = renderWidget();
- mockResults(1);
-
- widget.searchString = "#book AND tolkien";
- await widget.search();
-
- expect(server.get).toHaveBeenCalledWith(`quick-search/${encodeURIComponent("#book AND tolkien")}`);
-
- widget.$widget.find(".show-in-full-search").trigger("click");
- expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "#book AND tolkien" });
- });
-
- it("keeps the full search link pinned below the scrolling results", async () => {
- const widget = renderWidget();
- mockResults(30);
-
- await widget.search();
-
- const $menu = widget.$widget.find(".dropdown-menu");
- const $footer = $menu.find(".quick-search-footer");
-
- // The results scroll on their own, so the footer stays visible at the bottom of the menu.
- expect($menu.find(".quick-search-results .show-in-full-search").length).toBe(0);
- expect($menu.children().last().is($footer)).toBe(true);
- expect($footer.hasClass("hidden-ext")).toBe(false);
- expect($footer.find(".show-in-full-search").length).toBe(1);
- });
-
- it("hides the full search link while searching and when nothing matches", async () => {
- const widget = renderWidget();
- mockResults(3);
- await widget.search();
-
- const $footer = widget.$widget.find(".quick-search-footer");
- expect($footer.hasClass("hidden-ext")).toBe(false);
-
- mockResults(0);
- const search = widget.search();
- expect($footer.hasClass("hidden-ext")).toBe(true);
-
- await search;
- expect($footer.hasClass("hidden-ext")).toBe(true);
- });
-
- it("runs the full search from the pinned link, by click and by Enter", async () => {
- const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockResolvedValue(undefined);
- const widget = renderWidget();
- mockResults(3);
- await widget.search();
-
- const $link = widget.$widget.find(".show-in-full-search");
- $link.trigger("click");
- expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "hello" });
-
- triggerCommand.mockClear();
- $link[0].dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", code: "Enter", bubbles: true }));
- expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "hello" });
- });
-});
-
-function renderWidget() {
- const widget = new QuickSearchWidget();
- widget.render();
- widget.$widget.appendTo(document.body);
- widget.searchString = "hello";
- return widget;
-}
-
-function mockResults(count: number) {
- const searchResults = Array.from({ length: count }, (_, index) => ({
- notePath: `note${index}`,
- noteTitle: `Note ${index}`,
- notePathTitle: `Note ${index}`,
- highlightedNotePathTitle: `Note ${index}`,
- icon: "bx bx-note"
- }));
-
- vi.spyOn(server, "get").mockResolvedValue({
- searchResultNoteIds: searchResults.map((result) => result.notePath),
- searchResults,
- highlightedTokens: ["hello"],
- error: ""
- } as never);
-}
diff --git a/apps/client/src/widgets/quick_search_old.ts b/apps/client/src/widgets/quick_search_old.ts
index a566d886ee..84d176fe7e 100644
--- a/apps/client/src/widgets/quick_search_old.ts
+++ b/apps/client/src/widgets/quick_search_old.ts
@@ -1,10 +1,7 @@
import type { QuickSearchResponse } from "@triliumnext/commons";
import { Dropdown, Tooltip } from "bootstrap";
-import appContext from "../components/app_context.js";
-import { t } from "../services/i18n.js";
import server from "../services/server.js";
-import shortcutService from "../services/shortcuts.js";
import { handleRightToLeftPlacement } from "../services/utils.js";
import BasicWidget from "./basic_widget.js";
@@ -16,10 +13,6 @@ const TPL = /*html*/`
</button>
<div class="dropdown-menu tn-dropdown-list">
<div class="quick-search-results"></div>
- <div class="quick-search-footer hidden-ext">
- <div class="dropdown-divider"></div>
- <a class="dropdown-item show-in-full-search" tabindex="0">${t("quick-search.show-in-full-search")}</a>
- </div>
</div>
</div>
</div>`;
@@ -29,11 +22,9 @@ export default class QuickSearchWidget extends BasicWidget {
private dropdown!: bootstrap.Dropdown;
/** The query, set by the field that holds it. */
searchString = "";
- private $footer!: JQuery<HTMLElement>;
doRender() {
this.$widget = $(TPL);
- this.$footer = this.$widget.find(".quick-search-footer");
this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']")[0], {
popperConfig: {
@@ -42,10 +33,6 @@ export default class QuickSearchWidget extends BasicWidget {
}
});
- const $showInFullSearchButton = this.$footer.find(".show-in-full-search");
- $showInFullSearchButton.on("click", () => this.showInFullSearch());
- shortcutService.bindElShortcut($showInFullSearchButton, "return", () => this.showInFullSearch());
-
return this.$widget;
}
@@ -57,9 +44,7 @@ export default class QuickSearchWidget extends BasicWidget {
return;
}
- this.$footer.addClass("hidden-ext");
-
- const { searchResults, error } = await server.get<QuickSearchResponse>(`quick-search/${encodeURIComponent(searchString)}`);
+ const { error } = await server.get<QuickSearchResponse>(`quick-search/${encodeURIComponent(searchString)}`);
if (error) {
const tooltip = new Tooltip(this.$widget[0], {
@@ -72,17 +57,5 @@ export default class QuickSearchWidget extends BasicWidget {
setTimeout(() => tooltip.dispose(), 4000);
}
-
- if (searchResults.length) {
- this.$footer.removeClass("hidden-ext");
- }
- }
-
- async showInFullSearch() {
- this.dropdown.hide();
-
- await appContext.triggerCommand("searchNotes", {
- searchString: this.searchString
- });
}
}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.html
index 7fcf0ae87b..287bf2c979 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.html
@@ -28,13 +28,16 @@
below the note title. This preview shows the context where your search
terms appear, making it easier to identify the right note without opening
it.</p>
-<h3>Infinite Scrolling</h3>
-<p>Results are loaded progressively as you scroll:</p>
-<ul>
- <li>Initial display shows 15 results</li>
- <li>Scrolling near the bottom automatically loads 10 more results</li>
- <li>Continue scrolling to load all matching notes</li>
-</ul>
+<h3>All results in one list</h3>
+<p>Quick search lists up to 200 matching notes in a single scrollable list,
+ so the scrollbar shows how many results there are and how far through them
+ you are.</p>
+<h3>Continuing in the full search</h3>
+<p>To refine a query with the options of the full <a class="reference-link"
+ href="#root/_help_eIg8jdvaoNNd">Search</a>, click <em>Show in full search</em> below
+ the results, or press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> in the search field.
+ The full search opens in a new tab with the same query. The button stays
+ below the list, however far the results are scrolled.</p>
<h3>Visual Features</h3>
<ul>
<li><strong>Highlighting</strong>: Search terms appear in bold with accent
@@ -66,15 +69,19 @@
empty.</p>
<h3>Keyboard Navigation</h3>
<ul>
- <li>Press <code>Enter</code> to open the first result</li>
- <li>Use arrow keys to navigate through results</li>
- <li>Press <code>Escape</code> to close the quick search</li>
+ <li>Press <kbd>Enter</kbd> in the search field to search, or to refresh the
+ results already shown.</li>
+ <li>Press <kbd>Down</kbd> in the search field to move to the first result, then <kbd>Up</kbd> and <kbd>Down</kbd> to
+ move between results. <kbd>Up</kbd> on the first result returns to the search
+ field.</li>
+ <li>Press <kbd>Enter</kbd> on a result to open it.</li>
+ <li>Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to open the query in the full search.</li>
+ <li>Press <kbd>Escape</kbd> to close the results.</li>
</ul>
<h2>Using Quick Search</h2>
<ol>
<li><strong>Typo tolerance</strong>: Search finds results despite minor typos</li>
<li><strong>Content previews</strong>: 200-character snippets show match context</li>
- <li><strong>Infinite scrolling</strong>: Additional results load on scroll</li>
<li><strong>Specific terms</strong>: Specific search terms return more focused
results</li>
<li><strong>Match locations</strong>: Bold text indicates where matches occur</li>
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.md
index 730b6c2b93..4ec85b8bd0 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick search.md
@@ -22,13 +22,13 @@ Quick search includes the following features:
Search results now display a 200-character preview of the note content below the note title. This preview shows the context where your search terms appear, making it easier to identify the right note without opening it.
-### Infinite Scrolling
+### All results in one list
-Results are loaded progressively as you scroll:
+Quick search lists up to 200 matching notes in a single scrollable list, so the scrollbar shows how many results there are and how far through them you are.
-* Initial display shows 15 results
-* Scrolling near the bottom automatically loads 10 more results
-* Continue scrolling to load all matching notes
+### Continuing in the full search
+
+To refine a query with the options of the full <a class="reference-link" href="Search.md">Search</a>, click _Show in full search_ below the results, or press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> in the search field. The full search opens in a new tab with the same query. The button stays below the list, however far the results are scrolled.
### Visual Features
@@ -56,17 +56,18 @@ To search the whole database while hoisted, use the full <a class="reference-li
### Keyboard Navigation
-* Press `Enter` to open the first result
-* Use arrow keys to navigate through results
-* Press `Escape` to close the quick search
+* Press <kbd>Enter</kbd> in the search field to search, or to refresh the results already shown.
+* Press <kbd>Down</kbd> in the search field to move to the first result, then <kbd>Up</kbd> and <kbd>Down</kbd> to move between results. <kbd>Up</kbd> on the first result returns to the search field.
+* Press <kbd>Enter</kbd> on a result to open it.
+* Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to open the query in the full search.
+* Press <kbd>Escape</kbd> to close the results.
## Using Quick Search
1. **Typo tolerance**: Search finds results despite minor typos
2. **Content previews**: 200-character snippets show match context
-3. **Infinite scrolling**: Additional results load on scroll
-4. **Specific terms**: Specific search terms return more focused results
-5. **Match locations**: Bold text indicates where matches occur
+3. **Specific terms**: Specific search terms return more focused results
+4. **Match locations**: Bold text indicates where matches occur
## Quick Search - Exact Match Operator