Skip to content

Build your personal knowledge base with Trilium Notes

feat(markdown): let the @ note query run past spaces, as in text notes

Elian Doran3e889bdcfb65
diff --git a/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts b/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts
index a602bfc4dd..e2477fdb7d 100644
--- a/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts
+++ b/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts
@@ -184,9 +184,11 @@ describe("markdownCompletionAt", () => {
it("finds a note at the start of a line or after whitespace, from its @, by what follows it", () => {
expect(at("@")).toEqual({ kind: "note", from: 0, query: "" });
expect(at("see @Alp")).toEqual({ kind: "note", from: 4, query: "Alp" });
- // An address is no mention, and a space ends one.
+ // A title holds spaces, as the text editor's `@` allows, from the last `@` on.
+ expect(at("see @My meeting notes")).toEqual({ kind: "note", from: 4, query: "My meeting notes" });
+ expect(at("@a and @b c")).toEqual({ kind: "note", from: 7, query: "b c" });
+ // An address is no mention.
expect(at("mail [email protected]")).toBeNull();
- expect(at("see @Alpha ")).toBeNull();
expect(at("text `a @` b", 9)).toBeNull();
});
diff --git a/apps/client/src/widgets/type_widgets/markdown/completions.tsx b/apps/client/src/widgets/type_widgets/markdown/completions.tsx
index 7906edde87..f6107130e6 100644
--- a/apps/client/src/widgets/type_widgets/markdown/completions.tsx
+++ b/apps/client/src/widgets/type_widgets/markdown/completions.tsx
@@ -130,8 +130,8 @@ export function markdownCompletionAt(before: string, _explicit: boolean, state:
}
const COMMAND_TYPED = new RegExp(`${SLASH_COMMAND_REGEX.source}$`);
-/** An `@`, and the start of a note's title typed after it, up to a space. */
-const NOTE_TYPED = /(?:^|(?<=\s))@[^\s@]*$/;
+/** An `@`, and the note title typed after it, spaces included, as the text editor's `@` allows. */
+const NOTE_TYPED = /(?:^|(?<=\s))@[^@]*$/;
/**
* The commands the `/` list offers, titled, described, found by the same words and drawn with the same
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html
index f8d1f2b09d..d2203deb47 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html
@@ -218,9 +218,11 @@
Wikilinks-like format (<code>[[noteId]]</code>), which the preview shows
as an <a class="reference-link" href="#root/_help_hrZ1D00cLbal">internal link</a> with
the note's title.</p>
-<p>The search runs on the text typed after the <code>@</code> up to the next
- space. If no note fits, the list offers to create one, as a child of the
- Markdown note or in the inbox; the link is inserted once the note is created.</p>
+<p>The search runs on everything typed after the <code>@</code>, spaces included,
+ so a title such as <code>@My meeting notes</code> can be typed out; press <kbd>Esc</kbd> to
+ close the list and go on writing. If no note fits, the list offers to create
+ one, as a child of the Markdown note or in the inbox; the link is inserted
+ once the note is created.</p>
<p>Like slash commands, <code>@</code> does nothing inside code blocks and
inline code.</p>
<h4>Code block language auto-completion</h4>
diff --git a/docs/User Guide/User Guide/Note Types/Markdown.md b/docs/User Guide/User Guide/Note Types/Markdown.md
index d1aa40512c..a51c606760 100644
--- a/docs/User Guide/User Guide/Note Types/Markdown.md
+++ b/docs/User Guide/User Guide/Note Types/Markdown.md
@@ -179,7 +179,7 @@ Note that slash commands only work outside of code blocks and inline code.
As in <a class="reference-link" href="Text.md">Text</a> notes, typing `@` at the start of a line or after a space opens the note search. Picking a note replaces what was typed with a link to it in the Wikilinks-like format (`[[noteId]]`), which the preview shows as an <a class="reference-link" href="Text/Links/Internal%20(reference)%20links.md">internal link</a> with the note's title.
-The search runs on the text typed after the `@` up to the next space. If no note fits, the list offers to create one, as a child of the Markdown note or in the inbox; the link is inserted once the note is created.
+The search runs on everything typed after the `@`, spaces included, so a title such as `@My meeting notes` can be typed out; press <kbd>Esc</kbd> to close the list and go on writing. If no note fits, the list offers to create one, as a child of the Markdown note or in the inbox; the link is inserted once the note is created.
Like slash commands, `@` does nothing inside code blocks and inline code.