Skip to content

Build your personal knowledge base with Trilium Notes

fix(search): keep spaces in an @ note mention

Elian Doran5fc211c61a38
diff --git a/apps/client/src/widgets/search/search_completions.spec.ts b/apps/client/src/widgets/search/search_completions.spec.ts
index eb3d0278a4..76e39dbeaf 100644
--- a/apps/client/src/widgets/search/search_completions.spec.ts
+++ b/apps/client/src/widgets/search/search_completions.spec.ts
@@ -309,6 +309,13 @@ describe("searchCompletionAt", () => {
// `@` is a name character to the lexer, so the names go on being offered.
expect(complete("#foo@")).toMatchObject({ kind: "attributes", query: "foo@" });
});
+
+ it("keeps a title with spaces in the query, up to the next attribute or bracket", () => {
+ expect(complete("@Lord of the ")).toEqual({ kind: "notes", from: 0, query: "Lord of the " });
+ expect(complete("#author = @J. R. R")).toEqual({ kind: "notes", from: 10, query: "J. R. R" });
+
+ expect(complete("@Lord of #bo")).toMatchObject({ kind: "attributes", query: "bo" });
+ });
});
});
diff --git a/apps/client/src/widgets/search/search_completions.ts b/apps/client/src/widgets/search/search_completions.ts
index 6cd7c8d82a..e71bd337d2 100644
--- a/apps/client/src/widgets/search/search_completions.ts
+++ b/apps/client/src/widgets/search/search_completions.ts
@@ -104,9 +104,10 @@ export function searchCompletionAt(before: string, explicit: boolean): SearchCom
/**
* A note picked with `@`, which opens only where a value can stand — at the start, or after
* whitespace, an opening bracket or an operator. `@` is a name character to the lexer, so one
- * typed inside an attribute name is left alone.
+ * typed inside an attribute name is left alone. A pick replaces the mention, so the spaces of a
+ * title are part of it until an attribute, a bracket, a quote or a line break ends it.
*/
-const NOTE_MENTION = /(?:^|[\s(=!*<>%~])@[^\s#~()'"`@]*/;
+const NOTE_MENTION = /(?:^|[\s(=!*<>%~])@(?:[^\s#~()'"`@]| )*/;
/** The characters an operator is spelled with, so typing any of them starts offering them. */
const OPERATOR_PREFIX = /[=!*<>%~]+/;
const WORD_PREFIX = /[a-zA-Z]+/;