Skip to content

Build your personal knowledge base with Trilium Notes

feat(autocomplete): name the destination in the create-note row

Elian Doranc3b1e3b70b44
diff --git a/apps/client/src/services/date_notes.ts b/apps/client/src/services/date_notes.ts
index 838f1d3c75..2718d84f64 100644
--- a/apps/client/src/services/date_notes.ts
+++ b/apps/client/src/services/date_notes.ts
@@ -1,4 +1,4 @@
-import { dayjs } from "@triliumnext/commons";
+import { dayjs, type InboxTargetResponse } from "@triliumnext/commons";
import type { FNoteRow } from "../entities/fnote.js";
import froca from "./froca.js";
@@ -18,6 +18,14 @@ async function getInboxNotePath() {
return inboxNote?.getBestNotePathString();
}
+/**
+ * Names where `getInboxNote()` would place a note, without creating the day note it would
+ * otherwise create. Honours the hoisted note, which the server reads from the request.
+ */
+async function getInboxTarget() {
+ return await server.get<InboxTargetResponse>("special-notes/inbox-target");
+}
+
async function getTodayNote() {
return await getDayNote(dayjs().format("YYYY-MM-DD"));
}
@@ -143,6 +151,7 @@ async function getRecentLlmChats(limit: number = 10): Promise<RecentLlmChat[]> {
export default {
getInboxNote,
getInboxNotePath,
+ getInboxTarget,
getTodayNote,
getDayNote,
getWeekFirstDayNote,
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.ts
index 4da348e20f..1b3a45fdb5 100644
--- a/apps/client/src/services/note_autocomplete.spec.ts
+++ b/apps/client/src/services/note_autocomplete.spec.ts
@@ -3,13 +3,17 @@ import $ from "jquery";
// --- Mocks (hoisted above imports) ---
-const { triggerCommand, getActiveContextNoteId, getActiveContext, chooseNoteType, createNote, getInboxNotePath, getAllCommands, searchCommands } = vi.hoisted(() => ({
+const { triggerCommand, getActiveContextNoteId, getActiveContext, chooseNoteType, createNote, getInboxNotePath, getInboxTarget, translate, getAllCommands, searchCommands } = vi.hoisted(() => ({
triggerCommand: vi.fn(),
getActiveContextNoteId: vi.fn<() => string | null>(() => "activeNote"),
getActiveContext: vi.fn<() => any>(() => ({ hoistedNoteId: "hoisted" })),
chooseNoteType: vi.fn(),
createNote: vi.fn(),
getInboxNotePath: vi.fn<() => Promise<string | undefined>>(async () => "root/inbox"),
+ getInboxTarget: vi.fn<() => Promise<unknown>>(async () => ({ kind: "inbox", noteId: "inb", title: "Inbox" })),
+ // i18next is never initialised here, so the real `t` returns undefined. Echoing the key
+ // keeps the label assertions about which string is chosen rather than about its English.
+ translate: vi.fn((key: string, _opts?: Record<string, unknown>) => key),
getAllCommands: vi.fn(() => [] as any[]),
searchCommands: vi.fn(() => [] as any[])
}));
@@ -29,7 +33,12 @@ vi.mock("./note_create.js", () => ({
}));
vi.mock("./date_notes.js", () => ({
- default: { getInboxNotePath }
+ default: { getInboxNotePath, getInboxTarget }
+}));
+
+vi.mock("./i18n.js", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("./i18n.js")>()),
+ t: translate
}));
vi.mock("./command_registry.js", () => ({
@@ -291,6 +300,40 @@ describe("autocompleteSource (via dataset)", () => {
expect(rows[2].noteTitle).toBe("Existing");
});
+ it.each([
+ { kind: "inbox", title: "Inbox" },
+ { kind: "workspaceInbox", title: "Work" },
+ { kind: "workspaceRoot", title: "Project" }
+ ])("names the $kind destination in the create-note row", async ({ kind, title }) => {
+ getInboxTarget.mockResolvedValueOnce({ kind, title });
+ server.get = vi.fn(async () => []) as typeof server.get;
+ const { dataset } = initAndGetSource({ allowCreatingNotes: true });
+ const rows = await runSource(dataset, "New");
+ expect(rows[0].highlightedNotePathTitle).toBe("note_autocomplete.create-note-into");
+ expect(translate).toHaveBeenCalledWith("note_autocomplete.create-note-into", { term: "New", parentTitle: title });
+ });
+
+ it("names the day note, which has no title of its own until it is created", async () => {
+ getInboxTarget.mockResolvedValueOnce({ kind: "dayNote" });
+ server.get = vi.fn(async () => []) as typeof server.get;
+ const { dataset } = initAndGetSource({ allowCreatingNotes: true });
+ const rows = await runSource(dataset, "New");
+ expect(rows[0].highlightedNotePathTitle).toBe("note_autocomplete.create-note-into-day-note");
+ expect(translate).toHaveBeenCalledWith("note_autocomplete.create-note-into-day-note", { term: "New" });
+ });
+
+ it.each([
+ { when: "the lookup fails", arrange: () => getInboxTarget.mockRejectedValueOnce(new Error("nope")) },
+ { when: "the destination has no title", arrange: () => getInboxTarget.mockResolvedValueOnce({ kind: "inbox" }) }
+ ])("falls back to an unqualified label when $when", async ({ arrange }) => {
+ arrange();
+ server.get = vi.fn(async () => []) as typeof server.get;
+ const { dataset } = initAndGetSource({ allowCreatingNotes: true });
+ const rows = await runSource(dataset, "New");
+ expect(rows[0].action).toBe("create-note");
+ expect(rows[0].highlightedNotePathTitle).toBe("note_autocomplete.create-note");
+ });
+
it("uses root as the child-note parent when there is no active note", async () => {
getActiveContextNoteId.mockReturnValue(null);
server.get = vi.fn(async () => []) as typeof server.get;
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts
index 2343718e27..be57179b58 100644
--- a/apps/client/src/services/note_autocomplete.ts
+++ b/apps/client/src/services/note_autocomplete.ts
@@ -1,4 +1,5 @@
import type { MentionFeedObjectItem } from "@triliumnext/ckeditor5";
+import type { InboxTargetResponse } from "@triliumnext/commons";
import appContext from "../components/app_context.js";
import commandRegistry from "./command_registry.js";
@@ -8,6 +9,7 @@ import { t } from "./i18n.js";
import noteCreateService from "./note_create.js";
import server from "./server.js";
import { escapeHtml } from "./utils.js";
+import { logError } from "./ws.js";
// this key needs to have this value, so it's hit by the tooltip
const SELECTED_NOTE_PATH_KEY = "data-note-path";
@@ -26,6 +28,30 @@ function getSearchDelay(notesCount: number): number {
}
let searchDelay = getSearchDelay(notesCount);
+async function getInboxTarget() {
+ try {
+ return await dateNoteService.getInboxTarget();
+ } catch (e) {
+ // A destination that cannot be named is not worth failing the dropdown over: the
+ // entry falls back to a label without one.
+ logError(`Unable to resolve the inbox target: ${e}`);
+ return null;
+ }
+}
+
+/** Labels the creation entry with the note the capture would land in. */
+function buildCreateNoteTitle(term: string, target: InboxTargetResponse | null) {
+ if (!target || (target.kind !== "dayNote" && !target.title)) {
+ return t("note_autocomplete.create-note", { term });
+ }
+
+ if (target.kind === "dayNote") {
+ return t("note_autocomplete.create-note-into-day-note", { term });
+ }
+
+ return t("note_autocomplete.create-note-into", { term, parentTitle: target.title });
+}
+
// TODO: Deduplicate with server.
export interface Suggestion {
noteTitle?: string;
@@ -126,18 +152,22 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => void
const activeNoteId = appContext.tabManager.getActiveContextNoteId();
const length = term.trim().length;
+ // Started before the search rather than after it, so naming the destination costs a request
+ // but no extra wait.
+ const pendingInboxTarget = length >= 1 && options.allowCreatingNotes ? getInboxTarget() : null;
+
let results = await server.get<Suggestion[]>(`autocomplete?query=${encodeURIComponent(term)}&activeNoteId=${activeNoteId}&fastSearch=${fastSearch}`);
options.fastSearch = true;
// Both rows stay above the results: the CKEditor mention feed renders only the first
// `mention.dropdownLimit` items, and the jQuery dropdown scrolls past as many as 200.
- if (length >= 1 && options.allowCreatingNotes) {
+ if (pendingInboxTarget) {
results = [
{
action: "create-note",
noteTitle: term,
- highlightedNotePathTitle: t("note_autocomplete.create-note", { term })
+ highlightedNotePathTitle: buildCreateNoteTitle(term, await pendingInboxTarget)
} as Suggestion,
{
action: "create-child-note",
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 58571662bc..5675fba742 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2978,6 +2978,8 @@
"note_autocomplete": {
"search-for": "Search for \"{{term}}\"",
"create-note": "Create note \"{{term}}\"",
+ "create-note-into": "Create note \"{{term}}\" in {{parentTitle}}",
+ "create-note-into-day-note": "Create note \"{{term}}\" in today's day note",
"create-child-note": "Create child note \"{{term}}\"",
"insert-external-link": "Insert external link to \"{{term}}\"",
"clear-text-field": "Clear text field",
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html
index 1024fc9de5..abb3236d00 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html
@@ -22,10 +22,17 @@
<li>Using the keyboard, use the up or down arrow keys to navigate between
items. Press <kbd>Enter</kbd> to open the desired note.</li>
<li>If the note doesn't exist, it's possible to create it by typing the desired
- note title and selecting one of two options: <em>Create note</em> places
- it in the&nbsp;<a class="reference-link" href="#root/_help_S0Fos78ZfcY7">Note Inbox</a>,
- whereas <em>Create child note</em> places it under the note that is currently
- open.</li>
+ note title and selecting one of two options:
+ <ul>
+ <li><em>Create note</em> places it in the&nbsp;<a class="reference-link" href="#root/_help_S0Fos78ZfcY7">Note Inbox</a>:
+ the note labelled <code spellcheck="false">#inbox</code>, or today's&nbsp;<a class="reference-link"
+ href="#root/_help_l0tKav7yLHGF">Day Notes</a>&nbsp;if there is none. While
+ hoisted into a&nbsp;<a class="reference-link" href="#root/_help_9sRHySam5fXb">Workspaces</a>,
+ the workspace's own inbox is used, falling back to the workspace root itself.</li>
+ <li><em>Create child note</em> places it under the note that is currently
+ open.</li>
+ </ul>
+ </li>
</ul>
<h2>Recent notes</h2>
<p>Jump to note also has the ability to show the list of recently viewed
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html
index b5b13cac38..5e2e617c74 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html
@@ -18,7 +18,8 @@
<p>Only one note should carry this label. If there are multiple notes, only
one will be used by the application.</p>
<aside class="admonition note">
- <p>If there is no inbox note, Trilium will fall back to today's <a href="#root/_help_l0tKav7yLHGF">day note</a> instead.</p>
+ <p>If there is no inbox note, Trilium will fall back to today's <a href="#root/_help_l0tKav7yLHGF">day note</a> instead,
+ creating it and its calendar ancestors if they do not exist yet.</p>
</aside>
<h2>Workspace inboxes</h2>
<p>Each <a href="#root/_help_9sRHySam5fXb">workspace</a> can have its own inbox,
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html
index 461bcb2299..22254331e0 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html
@@ -12,8 +12,9 @@
<li>Searching for the title of the desired note to link. It's also possible
to create new notes from this dialog by typing a non-existing note title
and selecting either <em>Create note</em>, which places it in the&nbsp;<a class="reference-link"
- href="#root/_help_S0Fos78ZfcY7">Note Inbox</a>, or <em>Create child note</em>,
- which places it under the note being edited.</li>
+ href="#root/_help_S0Fos78ZfcY7">Note Inbox</a>&nbsp;(today's day note if no
+ inbox is set), or <em>Create child note</em>, which places it under the note
+ being edited.</li>
</ol>
<p>There are two link types which you can select when creating the link to
the note:</p>
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md
index ba9f160af2..6625487c7c 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md
@@ -16,7 +16,9 @@ In addition to searching for notes, it is also possible to search for commands.
* By default, when there is no text entered it will display the most recent notes.
* Using the keyboard, use the up or down arrow keys to navigate between items. Press <kbd>Enter</kbd> to open the desired note.
-* If the note doesn't exist, it's possible to create it by typing the desired note title and selecting one of two options: _Create note_ places it in the <a class="reference-link" href="../Notes/Note%20Inbox.md">Note Inbox</a>, whereas _Create child note_ places it under the note that is currently open.
+* If the note doesn't exist, it's possible to create it by typing the desired note title and selecting one of two options:
+ * _Create note_ places it in the <a class="reference-link" href="../Notes/Note%20Inbox.md">Note Inbox</a>: the note labelled `#inbox`, or today's <a class="reference-link" href="../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md">Day Notes</a> if there is none. While hoisted into a <a class="reference-link" href="Workspaces.md">Workspaces</a>, the workspace's own inbox is used, falling back to the workspace root itself.
+ * _Create child note_ places it under the note that is currently open.
## Recent notes
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md
index f0866cb059..0407bc2780 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md
@@ -16,7 +16,7 @@ To create a note inbox, apply the `#inbox` [label](../../Advanced%20Usage/Attrib
Only one note should carry this label. If there are multiple notes, only one will be used by the application.
> [!NOTE]
-> If there is no inbox note, Trilium will fall back to today's [day note](../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md) instead.
+> If there is no inbox note, Trilium will fall back to today's [day note](../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md) instead, creating it and its calendar ancestors if they do not exist yet.
## Workspace inboxes
diff --git a/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md b/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md
index 636b447f78..a0815ef91f 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md
@@ -8,7 +8,7 @@ You can open an internal link by clicking it. You can also see a read-only previ
Internal links can be created at the current position in a text note by:
1. Pressing <kbd>Ctrl</kbd> + <kbd>L</kbd> or the <img src="Internal (reference) links_image.png" width="20" height="17"> button underneath the <img src="1_Internal (reference) links_image.png" width="34" height="16"> menu in the <a class="reference-link" href="../Formatting%20toolbar.md">Formatting toolbar</a>.
-2. Searching for the title of the desired note to link. It's also possible to create new notes from this dialog by typing a non-existing note title and selecting either _Create note_, which places it in the <a class="reference-link" href="../../../Basic%20Concepts%20and%20Features/Notes/Note%20Inbox.md">Note Inbox</a>, or _Create child note_, which places it under the note being edited.
+2. Searching for the title of the desired note to link. It's also possible to create new notes from this dialog by typing a non-existing note title and selecting either _Create note_, which places it in the <a class="reference-link" href="../../../Basic%20Concepts%20and%20Features/Notes/Note%20Inbox.md">Note Inbox</a> (today's day note if no inbox is set), or _Create child note_, which places it under the note being edited.
There are two link types which you can select when creating the link to the note:
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index 1fcf00731f..653f732101 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -793,6 +793,19 @@ export type SimilarNoteResponse = SimilarNote[];
export type SaveSearchNoteResponse = CloneResponse;
+/**
+ * Which rule decided where a quickly captured note goes. `dayNote` is the only one that
+ * names no note, because the day note is created when the capture happens.
+ */
+export type InboxTargetKind = "inbox" | "workspaceInbox" | "workspaceRoot" | "dayNote";
+
+/** Where `POST /api/notes/:id/children` would put a note captured into the inbox. */
+export interface InboxTargetResponse {
+ kind: InboxTargetKind;
+ noteId?: string;
+ title?: string;
+}
+
/** A font file note carrying `#customFont`, as the font picker in the options lists it. */
export interface UserFont {
noteId: string;
diff --git a/packages/trilium-core/src/routes/api/special_notes.ts b/packages/trilium-core/src/routes/api/special_notes.ts
index b28689a262..26097e5605 100644
--- a/packages/trilium-core/src/routes/api/special_notes.ts
+++ b/packages/trilium-core/src/routes/api/special_notes.ts
@@ -10,6 +10,10 @@ function getInboxNote(req: Request<{ date: string }>) {
return specialNotesService.getInboxNote(req.params.date);
}
+function getInboxTarget() {
+ return specialNotesService.getInboxTarget();
+}
+
function getDayNote(req: Request<{ date: string }>) {
const calendarRootId = req.query.calendarRootId;
const calendarRoot = typeof calendarRootId === "string" ? becca.getNoteOrThrow(calendarRootId) : null;
@@ -132,6 +136,7 @@ function saveLlmChat(req: Request<{ llmChatNoteId: string }>) {
export default {
getInboxNote,
+ getInboxTarget,
getDayNote,
getWeekFirstDayNote,
getWeekNote,
diff --git a/packages/trilium-core/src/routes/index.ts b/packages/trilium-core/src/routes/index.ts
index 0434443c98..9212befa49 100644
--- a/packages/trilium-core/src/routes/index.ts
+++ b/packages/trilium-core/src/routes/index.ts
@@ -257,6 +257,7 @@ export function buildSharedApiRoutes({ route, asyncRoute, asyncRouteWithoutTrans
apiRoute(PUT, "/api/notes/:noteId/clone-after/:afterBranchId", cloningApiRoute.cloneNoteAfter);
asyncApiRoute(GET, "/api/special-notes/inbox/:date", specialNotesRoute.getInboxNote);
+ apiRoute(GET, "/api/special-notes/inbox-target", specialNotesRoute.getInboxTarget);
asyncApiRoute(GET, "/api/special-notes/days/:date", specialNotesRoute.getDayNote);
asyncApiRoute(GET, "/api/special-notes/week-first-day/:date", specialNotesRoute.getWeekFirstDayNote);
asyncApiRoute(GET, "/api/special-notes/weeks/:week", specialNotesRoute.getWeekNote);
diff --git a/packages/trilium-core/src/services/special_notes.spec.ts b/packages/trilium-core/src/services/special_notes.spec.ts
index 97a4b1721f..baefc4dd0a 100644
--- a/packages/trilium-core/src/services/special_notes.spec.ts
+++ b/packages/trilium-core/src/services/special_notes.spec.ts
@@ -189,6 +189,58 @@ describe("special_notes (core, real DB)", () => {
});
});
+ describe("getInboxTarget", () => {
+ it("names the #inbox note at the root workspace", () => {
+ const inbox = becca.getNoteOrThrow("root").getChildNotes()[0];
+ vi.spyOn(attributeService, "getNoteWithLabel").mockReturnValue(inbox);
+
+ expect(specialNotes.getInboxTarget()).toEqual({
+ kind: "inbox",
+ noteId: inbox.noteId,
+ title: inbox.getTitleOrProtected()
+ });
+ });
+
+ it("reports the day note without creating it", () => {
+ vi.spyOn(attributeService, "getNoteWithLabel").mockReturnValue(null);
+ const noteCountBefore = Object.keys(becca.notes).length;
+
+ // No CLS context: reaching getDayNote() would need one, so this also proves it is
+ // never called.
+ expect(specialNotes.getInboxTarget()).toEqual({ kind: "dayNote", noteId: undefined, title: undefined });
+ expect(Object.keys(becca.notes).length).toBe(noteCountBefore);
+ });
+
+ it("still reports the day note when the journal has been deleted, because the capture recreates it", () => {
+ // Nulls both labels this path consults, #inbox and #calendarRoot.
+ vi.spyOn(attributeService, "getNoteWithLabel").mockReturnValue(null);
+
+ expect(specialNotes.getInboxTarget()).toMatchObject({ kind: "dayNote" });
+
+ // Not root: getInboxNote() rebuilds the calendar rather than falling back to it.
+ const created = getContext().init(() => specialNotes.getInboxNote("2026-05-29"));
+ expect(created.noteId).not.toBe("root");
+ expect(created.getParentNotes().some((p) => p.noteId === "root")).toBe(false);
+ });
+
+ it("distinguishes the workspace inbox, a plain inbox and the workspace root", () => {
+ const workspaceInbox = becca.getNoteOrThrow("root").getChildNotes()[0];
+ const plainInbox = becca.getNoteOrThrow("root").getChildNotes()[1];
+
+ const withBoth = makeWorkspaceStub({ "#workspaceInbox": workspaceInbox, "#inbox": plainInbox });
+ vi.spyOn(hoistedNoteService, "getWorkspaceNote").mockReturnValue(withBoth as any);
+ expect(specialNotes.getInboxTarget()).toMatchObject({ kind: "workspaceInbox", noteId: workspaceInbox.noteId });
+
+ const withPlainOnly = makeWorkspaceStub({ "#inbox": plainInbox });
+ vi.spyOn(hoistedNoteService, "getWorkspaceNote").mockReturnValue(withPlainOnly as any);
+ expect(specialNotes.getInboxTarget()).toMatchObject({ kind: "inbox", noteId: plainInbox.noteId });
+
+ const withNeither = makeWorkspaceStub({});
+ vi.spyOn(hoistedNoteService, "getWorkspaceNote").mockReturnValue(withNeither as any);
+ expect(specialNotes.getInboxTarget()).toMatchObject({ kind: "workspaceRoot", noteId: withNeither.noteId });
+ });
+ });
+
describe("createLauncher", () => {
it("creates a note launcher with the note-launcher template", () => {
const { success, note } = getContext().init(() =>
diff --git a/packages/trilium-core/src/services/special_notes.ts b/packages/trilium-core/src/services/special_notes.ts
index d92ff5d60b..cf86b78953 100644
--- a/packages/trilium-core/src/services/special_notes.ts
+++ b/packages/trilium-core/src/services/special_notes.ts
@@ -10,31 +10,51 @@ import SearchContext from "./search/search_context.js";
import { LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT } from "./hidden_subtree.js";
import { t } from "i18next";
import BNote from '../becca/entities/bnote.js';
-import { SaveLlmChatResponse, SaveSearchNoteResponse, SaveSqlConsoleResponse } from "@triliumnext/commons";
+import { InboxTargetKind, InboxTargetResponse, SaveLlmChatResponse, SaveSearchNoteResponse, SaveSqlConsoleResponse } from "@triliumnext/commons";
function getInboxNote(date: string) {
+ const { note } = resolveInboxTarget();
+
+ return note ?? dateNoteService.getDayNote(date);
+}
+
+/**
+ * Decides where a quickly captured note goes, without creating anything. `getInboxNote()`
+ * creates the day note it falls back to, so callers that only want to name the destination —
+ * the note autocomplete labels its creation entry with it — go through this instead.
+ */
+function resolveInboxTarget(): { kind: InboxTargetKind; note?: BNote } {
const workspaceNote = hoistedNoteService.getWorkspaceNote();
if (!workspaceNote) {
throw new Error("Unable to find workspace note");
}
- let inbox: BNote;
-
if (!workspaceNote.isRoot()) {
- inbox = workspaceNote.searchNoteInSubtree("#workspaceInbox");
-
- if (!inbox) {
- inbox = workspaceNote.searchNoteInSubtree("#inbox");
+ const workspaceInbox = workspaceNote.searchNoteInSubtree("#workspaceInbox");
+ if (workspaceInbox) {
+ return { kind: "workspaceInbox", note: workspaceInbox };
}
- if (!inbox) {
- inbox = workspaceNote;
+ const inbox = workspaceNote.searchNoteInSubtree("#inbox");
+ if (inbox) {
+ return { kind: "inbox", note: inbox };
}
- } else {
- inbox = attributeService.getNoteWithLabel("inbox") || dateNoteService.getDayNote(date);
+
+ return { kind: "workspaceRoot", note: workspaceNote };
+ }
+
+ const inbox = attributeService.getNoteWithLabel("inbox");
+ if (inbox) {
+ return { kind: "inbox", note: inbox };
}
- return inbox;
+ return { kind: "dayNote" };
+}
+
+function getInboxTarget(): InboxTargetResponse {
+ const { kind, note } = resolveInboxTarget();
+
+ return { kind, noteId: note?.noteId, title: note?.getTitleOrProtected() };
}
function createSqlConsole() {
@@ -389,6 +409,7 @@ function saveLlmChat(llmChatNoteId: string | null) {
export default {
getInboxNote,
+ getInboxTarget,
createSqlConsole,
saveSqlConsole,
createSearchNote,