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
feat(search): name the keys the search string field answers
Elian Dorana46ea9ad8f1d
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex e3b8f92198..2878113753 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1514,7 +1514,7 @@},"search_string": {"title_column": "Search string:",- "placeholder": "fulltext keywords, #tag = value...",+ "placeholder": "Ctrl+Space for suggestions, Shift+Enter for a new line, Enter to search","search_syntax": "Search syntax","also_see": "also see","complete_help": "complete help on search syntax",@@ -1526,7 +1526,13 @@"label_year_comparison": "numerical comparison (also >, >=, <).","label_date_created": "notes created in the last month","error": "Search error: {{error}}",- "search_prefix": "Search:"+ "search_prefix": "Search:",+ "hints": {+ "title": "Search string",+ "completions": "Show suggestions",+ "new_line": "New line",+ "run_search": "Run the search"+ }},"attachment_detail": {"open_help_page": "Open help page on attachments",diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.css b/apps/client/src/widgets/ribbon/SearchStringEditor.cssindex 46cc3e789a..382bc66d49 100644--- a/apps/client/src/widgets/ribbon/SearchStringEditor.css+++ b/apps/client/src/widgets/ribbon/SearchStringEditor.css@@ -101,6 +101,11 @@rather than from the placeholder. The text draws at the line's start either way. */position: absolute;color: var(--input-placeholder-color, var(--muted-text-color));+ font-family: var(--main-font-family);+ max-width: 100%;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;}/* CodeMirror puts a zero-width spacer before the placeholder widget and aligns it `text-top`,diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx b/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsxindex bfe8d26bc1..a4eda472bd 100644--- a/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx+++ b/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx@@ -2,7 +2,10 @@ import { render } from "preact";import { act } from "preact/test-utils";import { describe, expect, it, vi } from "vitest";+import Component from "../../components/component";+import { collectShortcutHints } from "../../services/shortcut_hints";import { renderInto } from "../../test/render";+import { ParentComponent } from "../react/react_utils";import SearchStringEditor from "./SearchStringEditor";// The completions fetch attribute names and values through the server; nothing here opens the popup.@@ -44,6 +47,27 @@ describe("SearchStringEditor", () => {editor.dispatch({ changes: { from: 11, insert: " = 1954" } });expect(onChange).toHaveBeenCalledWith("#book #year = 1954");});+ it("registers the keys the field answers on the host component", () => {+ const host = new Component();+ act(() => {+ renderInto(+ <ParentComponent.Provider value={host}>+ <SearchStringEditor noteId="search1" currentValue="#book" onChange={() => {}} onEnter={() => {}} />+ </ParentComponent.Provider>+ );+ });++ expect(collectShortcutHints(host)).toEqual([+ {+ titleKey: "search_string.hints.title",+ hints: [+ { keys: ["Ctrl+Space"], labelKey: "search_string.hints.completions" },+ { keys: ["Shift+Enter"], labelKey: "search_string.hints.new_line" },+ { keys: ["Enter"], labelKey: "search_string.hints.run_search" }+ ]+ }+ ]);+ });});interface Props {diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.tsx b/apps/client/src/widgets/ribbon/SearchStringEditor.tsxindex aefaad1f8f..f4c0ae6d45 100644--- a/apps/client/src/widgets/ribbon/SearchStringEditor.tsx+++ b/apps/client/src/widgets/ribbon/SearchStringEditor.tsx@@ -8,6 +8,8 @@ import { useEffect, useRef } from "preact/hooks";import { t } from "../../services/i18n";import server from "../../services/server";+import type { ShortcutHintDefinition } from "../../services/shortcut_hints";+import { useContextualShortcutHints } from "../react/hooks";import { searchCompletionIcon, searchCompletionReactivates, searchCompletionSource } from "./search_completions";interface SearchStringEditorProps {@@ -22,6 +24,19 @@ interface SearchStringEditorProps {onEnter(): void;}+// The keys the field answers, for the contextual shortcut pane (Alt+F1). CodeMirror binds+// Ctrl-Space on every platform, so it is a literal key list rather than a rebindable action.+const SEARCH_STRING_HINTS: ShortcutHintDefinition = [+ {+ titleKey: "search_string.hints.title",+ hints: [+ { keys: ["Ctrl+Space"], labelKey: "search_string.hints.completions" },+ { keys: ["Shift+Enter"], labelKey: "search_string.hints.new_line" },+ { keys: ["Enter"], labelKey: "search_string.hints.run_search" }+ ]+ }+];+/*** Edits the `#searchString` of a saved search in a CodeMirror editor. Enter runs the search and* Shift-Enter starts a new line, so a long query can be laid out over several of them.@@ -40,6 +55,8 @@ export default function SearchStringEditor({ currentValue, noteId, placeholder,// report it as an edit the user made.const isAdopting = useRef(false);+ useContextualShortcutHints(SEARCH_STRING_HINTS);+useEffect(() => {let editor: FieldEditor | undefined;let cancelled = false;