Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor: add the initial implementation for selection sorting

Adorian Doran690fba022cc8
diff --git a/apps/client/src/menus/note_context_menu.spec.ts b/apps/client/src/menus/note_context_menu.spec.ts
index b1e92b29eb..302de7af7d 100644
--- a/apps/client/src/menus/note_context_menu.spec.ts
+++ b/apps/client/src/menus/note_context_menu.spec.ts
@@ -37,6 +37,10 @@ vi.mock("./table_context_menu.js", () => ({
buildTableContextMenuSections: vi.fn(async () => null),
hasTableCellSelection: vi.fn(async () => false)
}));
+vi.mock("./text_editor_context_menu.js", async (importOriginal) => ({
+ ...await importOriginal<typeof import("./text_editor_context_menu.js")>(),
+ buildSortSelectionMenuItem: vi.fn(() => null)
+}));
import { buildBlockReferenceMenuItems } from "../services/block_reference.js";
import { copyHtml, copyTextWithToast } from "../services/clipboard_ext.js";
@@ -49,6 +53,7 @@ import {
hasTableCellSelection,
type TableMenuSections
} from "./table_context_menu.js";
+import { buildSortSelectionMenuItem } from "./text_editor_context_menu.js";
import {
buildNoteContextMenuItems,
type ContextMenuHost,
@@ -382,6 +387,34 @@ describe("buildNoteContextMenuItems", () => {
]);
});
+ it("puts the sort submenu below the clipboard rows, outside a table only", async () => {
+ const host = browserLikeHost({
+ paste: { enabled: true, run: vi.fn(), runAsPlainText: vi.fn(), read: vi.fn() }
+ });
+ vi.mocked(buildSortSelectionMenuItem).mockReturnValueOnce({ title: "SORT" });
+
+ const items = await build({ isEditable: true, element: document.createElement("p") }, host);
+
+ expect(titles(items)).toEqual([
+ "electron_context_menu.cut",
+ "electron_context_menu.copy",
+ "electron_context_menu.paste",
+ "---",
+ "SORT",
+ "---",
+ "electron_context_menu.search_online",
+ "electron_context_menu.search_in_trilium"
+ ]);
+
+ vi.mocked(buildSortSelectionMenuItem).mockClear();
+ vi.mocked(buildTableContextMenuSections).mockResolvedValueOnce({
+ main: [], sort: { title: "S" }, delete: [], select: { title: "SEL" }, pasteRows: []
+ } as TableMenuSections);
+ await build({ isEditable: true, element: document.createElement("td") }, host);
+ await build({ element: document.createElement("p") }, host);
+ expect(buildSortSelectionMenuItem).not.toHaveBeenCalled();
+ });
+
it("skips the table section for a non-editable target", async () => {
await build({ element: document.createElement("td") });
diff --git a/apps/client/src/menus/note_context_menu.ts b/apps/client/src/menus/note_context_menu.ts
index 31149734b0..32d8ede3e6 100644
--- a/apps/client/src/menus/note_context_menu.ts
+++ b/apps/client/src/menus/note_context_menu.ts
@@ -11,7 +11,10 @@ import { buildCodeEditorContextMenuItems } from "./code_editor_context_menu.js";
import contextMenu, { type MenuItem } from "./context_menu.js";
import { splitMenuItem } from "./context_menu_utils.js";
import { buildTableContextMenuSections, hasTableCellSelection } from "./table_context_menu.js";
-import { buildAiActionsMenuItem, getTextEditorAtSelection } from "./text_editor_context_menu.js";
+import {
+ buildAiActionsMenuItem, buildSortSelectionMenuItem, getTextEditorAtSelection,
+ getTextEditorContaining
+} from "./text_editor_context_menu.js";
/** What the pointer was over when the menu was summoned. */
export interface ContextMenuTarget {
@@ -144,6 +147,10 @@ export async function buildNoteContextMenuItems(
const codeEditorItems = target.isEditable
? await buildCodeEditorContextMenuItems(target.element)
: null;
+ // A table has its own sort section.
+ const sortItem = target.isEditable && !tableSections
+ ? buildSortSelectionMenuItem(await getTextEditorContaining(target.element))
+ : null;
const hasText = !hasCellSelection && target.selectionText.trim().length > 0;
const hasClipboardContent = hasText || hasCellSelection;
@@ -255,6 +262,10 @@ export async function buildNoteContextMenuItems(
...tableSections.delete, { kind: "separator" }, tableSections.select);
}
+ if (sortItem) {
+ items.push({ kind: "separator" }, sortItem);
+ }
+
if (codeEditorItems) {
items.push({ kind: "separator" }, ...codeEditorItems);
}
diff --git a/apps/client/src/menus/text_editor_context_menu.spec.ts b/apps/client/src/menus/text_editor_context_menu.spec.ts
index 6fd01841a9..7e3ee1bc97 100644
--- a/apps/client/src/menus/text_editor_context_menu.spec.ts
+++ b/apps/client/src/menus/text_editor_context_menu.spec.ts
@@ -1,11 +1,19 @@
-import type { AiQuickAction, AiQuickActionFooter, AiQuickActionGroup } from "@triliumnext/ckeditor5";
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import type {
+ AiQuickAction, AiQuickActionFooter, AiQuickActionGroup, CKTextEditor, SortTargetKind
+} from "@triliumnext/ckeditor5";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("../services/i18n.js", () => ({ t: (key: string) => key }));
+const experimentalState = vi.hoisted(() => ({ enabled: new Set<string>() }));
+vi.mock("../services/experimental_features.js", () => ({
+ isExperimentalFeatureEnabled: (id: string) => experimentalState.enabled.has(id)
+}));
import { setEditorNoteId } from "../widgets/react/NoteStore.js";
import type { MenuCommandItem, MenuItem } from "./context_menu.js";
-import { buildAiActionsMenuItem, getTextEditorAtSelection } from "./text_editor_context_menu.js";
+import {
+ buildAiActionsMenuItem, buildSortSelectionMenuItem, getTextEditorAtSelection
+} from "./text_editor_context_menu.js";
const GROUPS: AiQuickActionGroup[] = [
{
@@ -274,3 +282,55 @@ describe("buildAiActionsMenuItem", () => {
expect(await buildAiActionsMenuItem()).toBeNull();
});
});
+
+describe("buildSortSelectionMenuItem", () => {
+ beforeEach(() => experimentalState.enabled.add("sortSelection"));
+ afterEach(() => experimentalState.enabled.clear());
+
+ /** An editor whose sort commands are enabled for `kind`, over `blockCount` selected blocks. */
+ function sortEditor(kind: SortTargetKind | null = "blocks", blockCount = 2, isEnabled = true) {
+ const editor = {
+ commands: { get: () => ({ isEnabled, value: kind }) },
+ model: {
+ document: {
+ selection: { getSelectedBlocks: () => Array.from({ length: blockCount }) }
+ }
+ },
+ editing: { view: { focus: vi.fn() } },
+ execute: vi.fn()
+ };
+ return editor as typeof editor & CKTextEditor;
+ }
+
+ it("names the submenu after what it sorts, and sorts either way", () => {
+ const titlesByKind = ([ "blocks", "listItems", "rows" ] as const).map((kind) =>
+ (buildSortSelectionMenuItem(sortEditor(kind)) as MenuCommandItem<string>).title);
+ expect(titlesByKind).toEqual([
+ "sort_selection.sort_blocks",
+ "sort_selection.sort_list_items",
+ "sort_selection.sort_rows"
+ ]);
+
+ const editor = sortEditor();
+ const item = buildSortSelectionMenuItem(editor) as MenuCommandItem<string>;
+ const rows = commandItems(item.items ?? []);
+ expect(rows.map((row) => row.title))
+ .toEqual([ "sort_selection.ascending", "sort_selection.descending" ]);
+
+ rows[1].handler?.(rows[1], null as never);
+ expect(editor.execute).toHaveBeenCalledWith("triliumSortSelectionDescending");
+ expect(editor.editing.view.focus).toHaveBeenCalled();
+ rows[0].handler?.(rows[0], null as never);
+ expect(editor.execute).toHaveBeenLastCalledWith("triliumSortSelectionAscending");
+ });
+
+ it("is absent for one block, nothing to sort, no editor, or with the feature off", () => {
+ expect(buildSortSelectionMenuItem(sortEditor("blocks", 1))).toBeNull();
+ expect(buildSortSelectionMenuItem(sortEditor(null))).toBeNull();
+ expect(buildSortSelectionMenuItem(sortEditor("rows", 2, false))).toBeNull();
+ expect(buildSortSelectionMenuItem(null)).toBeNull();
+
+ experimentalState.enabled.clear();
+ expect(buildSortSelectionMenuItem(sortEditor())).toBeNull();
+ });
+});
diff --git a/apps/client/src/menus/text_editor_context_menu.ts b/apps/client/src/menus/text_editor_context_menu.ts
index d82e647d22..d5aebdf9bf 100644
--- a/apps/client/src/menus/text_editor_context_menu.ts
+++ b/apps/client/src/menus/text_editor_context_menu.ts
@@ -1,9 +1,13 @@
-import type { AiQuickAction, AiQuickActionFooter, AiQuickActionGroup, CKTextEditor } from "@triliumnext/ckeditor5";
+import type {
+ AiQuickAction, AiQuickActionFooter, AiQuickActionGroup, CKTextEditor, SortTargetKind
+} from "@triliumnext/ckeditor5";
import type { CommandNames } from "../components/app_context.js";
+import { isExperimentalFeatureEnabled } from "../services/experimental_features.js";
import { t } from "../services/i18n.js";
import { getEditorNoteId } from "../widgets/react/NoteStore.js";
import type { MenuItem } from "./context_menu.js";
+import { submenuItem } from "./context_menu_utils.js";
/**
* The "AI assistant" row of the text editor's right-click menu: the toolbar's split-button entry,
@@ -131,6 +135,36 @@ function buildQuickActionItems(
return items;
}
+/**
+ * The _Sort_ submenu for a selection over several blocks of `editor`, named by what it sorts. It
+ * is `null` while the experimental feature is off, for a selection inside one block, and when
+ * nothing at the selection can be sorted.
+ */
+export function buildSortSelectionMenuItem(
+ editor: CKTextEditor | null | undefined
+): MenuItem<CommandNames> | null {
+ const command = editor?.commands.get("triliumSortSelectionAscending");
+ if (!editor || !command?.isEnabled || !command.value
+ || !isExperimentalFeatureEnabled("sortSelection")
+ || Array.from(editor.model.document.selection.getSelectedBlocks()).length < 2) {
+ return null;
+ }
+
+ const sortItem = (title: string, uiIcon: string, commandName: SortSelectionCommandName) => ({
+ title,
+ uiIcon,
+ handler: () => {
+ editor.execute(commandName);
+ editor.editing.view.focus();
+ }
+ });
+ return submenuItem({ title: getSortMenuTitle(command.value), uiIcon: "bx bx-sort-alt-2" }, [
+ sortItem(t("sort_selection.ascending"), "bx bx-sort-up", "triliumSortSelectionAscending"),
+ sortItem(t("sort_selection.descending"), "bx bx-sort-down",
+ "triliumSortSelectionDescending")
+ ]);
+}
+
/**
* The text editor the live DOM selection sits in, or `null` when it sits anywhere else.
*
@@ -159,6 +193,19 @@ export async function getTextEditorContaining(
return editor && getEditorNoteId(editor) ? editor : null;
}
+type SortSelectionCommandName = "triliumSortSelectionAscending" | "triliumSortSelectionDescending";
+
+function getSortMenuTitle(kind: SortTargetKind) {
+ switch (kind) {
+ case "listItems":
+ return t("sort_selection.sort_list_items");
+ case "rows":
+ return t("sort_selection.sort_rows");
+ case "blocks":
+ return t("sort_selection.sort_blocks");
+ }
+}
+
/** The editable root of a text editor, which CKEditor gives a reference to the editor. */
type EditorRootElement = HTMLElement & { ckeditorInstance?: CKTextEditor | null };
diff --git a/apps/client/src/services/block_reference.spec.ts b/apps/client/src/services/block_reference.spec.ts
index cbd0cf151c..988c5cd9e9 100644
--- a/apps/client/src/services/block_reference.spec.ts
+++ b/apps/client/src/services/block_reference.spec.ts
@@ -13,8 +13,9 @@ import type { ViewScope } from "./link.js";
const {
showError, showMessage, showMenu, copyHtmlWithToast, copyTextWithToast, getTextEditorContaining,
- getNote, getNoteShareLink
+ getNote, getNoteShareLink, buildSortSelectionMenuItem
} = vi.hoisted(() => ({
+ buildSortSelectionMenuItem: vi.fn(),
getNoteShareLink: vi.fn(),
showError: vi.fn(),
showMessage: vi.fn(),
@@ -29,7 +30,9 @@ vi.mock("./i18n.js", () => ({
}));
vi.mock("./toast.js", () => ({ default: { showError, showMessage } }));
vi.mock("../menus/context_menu.js", () => ({ default: { show: showMenu } }));
-vi.mock("../menus/text_editor_context_menu.js", () => ({ getTextEditorContaining }));
+vi.mock("../menus/text_editor_context_menu.js", () => ({
+ buildSortSelectionMenuItem, getTextEditorContaining
+}));
vi.mock("./clipboard_ext.js", () => ({ copyHtmlWithToast, copyTextWithToast }));
vi.mock("./froca.js", () => ({ default: { getNote } }));
vi.mock("./content_renderer.js", () => ({
@@ -257,6 +260,7 @@ describe("openBlockHandleMenu", () => {
openBlockHandleMenu(event, 3, { copyReference });
openBlockHandleMenu(event, 3, { copyReference, copyShareLink });
+ openBlockHandleMenu(event, 3, { copyReference, sortItem: { title: "SORT" } });
expect(showMenu).toHaveBeenNthCalledWith(1, expect.objectContaining({
x: event.pageX,
@@ -269,6 +273,9 @@ describe("openBlockHandleMenu", () => {
handler: copyShareLink
}) ]
}));
+ expect(showMenu).toHaveBeenNthCalledWith(3, expect.objectContaining({
+ items: [ copyItem, { kind: "separator" }, { title: "SORT" } ]
+ }));
});
});
@@ -313,7 +320,7 @@ describe("buildReferenceConfig", () => {
});
it("opens the block handle menu, which copies a reference or the public link", async () => {
- const { config, save } = buildSource();
+ const { config, editor, save } = buildSource();
const event = new MouseEvent("contextmenu");
getNoteShareLink.mockReturnValue("https://notes.example.com/share/page");
@@ -332,6 +339,11 @@ describe("buildReferenceConfig", () => {
getNoteShareLink.mockReturnValue(null);
config.blockReference?.openHandleMenu?.(event, 1);
expect(showMenu.mock.calls[1][0].items).toHaveLength(1);
+
+ buildSortSelectionMenuItem.mockReturnValueOnce({ title: "SORT" });
+ config.blockReference?.openHandleMenu?.(event, 2);
+ expect(buildSortSelectionMenuItem).toHaveBeenCalledWith(editor);
+ expect(showMenu.mock.calls[2][0].items.at(-1)).toEqual({ title: "SORT" });
});
it("copies nothing before the editor or the note is there", async () => {
diff --git a/apps/client/src/services/block_reference.ts b/apps/client/src/services/block_reference.ts
index 9dcb4a8377..71a1cebbb3 100644
--- a/apps/client/src/services/block_reference.ts
+++ b/apps/client/src/services/block_reference.ts
@@ -11,7 +11,9 @@ import type { CommandNames } from "../components/app_context.js";
import type FNote from "../entities/fnote.js";
import contextMenu, { type MenuItem } from "../menus/context_menu.js";
import type { ClipboardAccess } from "../menus/table_context_menu.js";
-import { getTextEditorContaining } from "../menus/text_editor_context_menu.js";
+import {
+ buildSortSelectionMenuItem, getTextEditorContaining
+} from "../menus/text_editor_context_menu.js";
import { getBlockExcerpt } from "./block_excerpts.js";
import { copyHtmlWithToast, copyTextWithToast } from "./clipboard_ext.js";
import { revealElement } from "./collapsible.js";
@@ -48,6 +50,8 @@ export interface BlockHandleMenuActions {
copyReference: () => void;
/** Copies a link to the selected blocks on the shared page of the note, if it is shared. */
copyShareLink?: () => void;
+ /** The _Sort_ submenu, shown last. */
+ sortItem?: MenuItem<CommandNames> | null;
}
/** The note a text editor is open on, which the references it copies point to. */
@@ -86,7 +90,8 @@ export function buildReferenceConfig(
copyReference: () => void copy(copyBlockReference),
copyShareLink: shareLink
? () => void copy((editor) => copyBlockShareLink(editor, shareLink))
- : undefined
+ : undefined,
+ sortItem: buildSortSelectionMenuItem(source.getEditor())
});
},
copyReference: () => void copy(copyBlockReference)
@@ -101,7 +106,7 @@ export function buildReferenceConfig(
export function openBlockHandleMenu(
event: MouseEvent,
count: number,
- { copyReference, copyShareLink }: BlockHandleMenuActions
+ { copyReference, copyShareLink, sortItem }: BlockHandleMenuActions
) {
const items = [ getCopyItem(count, copyReference) ];
if (copyShareLink) {
@@ -111,6 +116,9 @@ export function openBlockHandleMenu(
handler: copyShareLink
});
}
+ if (sortItem) {
+ items.push({ kind: "separator" }, sortItem);
+ }
void contextMenu.show({
x: event.pageX,
diff --git a/apps/client/src/services/experimental_features.spec.ts b/apps/client/src/services/experimental_features.spec.ts
index 3ad57af7a4..d0b34ed881 100644
--- a/apps/client/src/services/experimental_features.spec.ts
+++ b/apps/client/src/services/experimental_features.spec.ts
@@ -25,7 +25,15 @@ describe("experimental_features", () => {
it("lists every feature", async () => {
const { mod } = await freshModule([]);
expect(mod.getAvailableExperimentalFeatures().map((f) => f.id))
- .toEqual(["llm", "extendedCodeBlocks"]);
+ .toEqual(["llm", "extendedCodeBlocks", "sortSelection"]);
+ });
+
+ it("names and describes every feature before the translations load", async () => {
+ const { mod } = await freshModule([]);
+ for (const feature of mod.getAvailableExperimentalFeatures()) {
+ expect(feature.name, feature.id).toMatch(/\S/);
+ expect(feature.description, feature.id).toMatch(/\S/);
+ }
});
it("llm enablement is driven by the aiEnabled option", async () => {
diff --git a/apps/client/src/services/experimental_features.ts b/apps/client/src/services/experimental_features.ts
index d1e2719bf3..b10d3738e6 100644
--- a/apps/client/src/services/experimental_features.ts
+++ b/apps/client/src/services/experimental_features.ts
@@ -1,4 +1,3 @@
-import { t } from "./i18n";
import options from "./options";
export interface ExperimentalFeature {
@@ -7,16 +6,25 @@ export interface ExperimentalFeature {
description: string;
}
+// Not translated: experimental features are temporary.
export const experimentalFeatures = [
{
id: "llm",
- name: t("experimental_features.llm_name"),
- description: t("experimental_features.llm_description"),
+ name: "AI / LLM Chat",
+ description: "Enable the AI chat sidebar and LLM chat notes powered by large language "
+ + "models."
},
{
id: "extendedCodeBlocks",
- name: t("experimental_features.extended_code_blocks_name"),
- description: t("experimental_features.extended_code_blocks_description")
+ name: "Extended code blocks",
+ description: "A faster code block with a more advanced syntax highlighting engine and "
+ + "code folding."
+ },
+ {
+ id: "sortSelection",
+ name: "Sort selection in text editor",
+ description: "Sort the selected paragraphs, list items or table rows of a text note from "
+ + "the formatting toolbar, the block handle and the context menu."
}
] as const satisfies ExperimentalFeature[];
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 692f00d75c..cb98e658fa 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1880,11 +1880,7 @@
},
"experimental_features": {
"title": "Experimental Options",
- "disclaimer": "These options are experimental and may cause instability. Use with caution.",
- "llm_name": "AI / LLM Chat",
- "llm_description": "Enable the AI chat sidebar and LLM chat notes powered by large language models.",
- "extended_code_blocks_name": "Extended code blocks",
- "extended_code_blocks_description": "A faster code block with a more advanced syntax highlighting engine and code folding."
+ "disclaimer": "These options are experimental and may cause instability. Use with caution."
},
"fonts": {
"theme_defined": "Theme defined",
@@ -4933,6 +4929,13 @@
"title": "Hide keyboard",
"close_menu": "Close menu"
},
+ "sort_selection": {
+ "sort_blocks": "Sort blocks",
+ "sort_list_items": "Sort list items",
+ "sort_rows": "Sort rows",
+ "ascending": "Ascending",
+ "descending": "Descending"
+ },
"code_editor_context_menu": {
"transform": "Transform",
"sort_ascending": "Sort ascending",
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
index dd71c0d5c4..8c8a7f1684 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
@@ -107,6 +107,35 @@ describe("the extended code block", () => {
});
});
+describe("the sort selection button", () => {
+ afterEach(() => experimentalState.enabled.clear());
+
+ /** The items each sort button follows: the indentation, or the block moves on a phone. */
+ function getPlacements() {
+ const mobile = buildMobileToolbar(true);
+ return [
+ [ buildClassicToolbar(false, true).toolbar.items, "indent" ],
+ [ buildFloatingToolbar(true).blockToolbar, "indent" ],
+ [ mobile.toolbar.items, "moveBlockDown" ],
+ [ mobile.listToolbar, "moveBlockDown" ]
+ ] as const;
+ }
+
+ it("follows the indentation or the block moves in every toolbar while it is on", () => {
+ experimentalState.enabled.add("sortSelection");
+ for (const [ items, previous ] of getPlacements()) {
+ const index = items.indexOf(previous);
+ expect(items.slice(index, index + 2)).toEqual([ previous, "sortSelection" ]);
+ }
+
+ experimentalState.enabled.clear();
+ for (const [ items, previous ] of getPlacements()) {
+ expect(items).toContain(previous);
+ expect(items).not.toContain("sortSelection");
+ }
+ });
+});
+
describe("the attach menu", () => {
it("replaces the image and file uploads on every toolbar, with the camera only on a phone", () => {
const classic = buildClassicToolbar(false, true);
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.ts b/apps/client/src/widgets/type_widgets/text/toolbar.ts
index e7a21ed4ce..5dc4b00234 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.ts
@@ -95,6 +95,7 @@ export function buildMobileToolbar(aiAssistant: boolean) {
"indent",
"moveBlockUp",
"moveBlockDown",
+ ...getSortSelectionItems(),
...(aiAssistant ? ["|", "aiAssistantMenu"] : [])
]
},
@@ -130,7 +131,7 @@ export function buildMobileToolbar(aiAssistant: boolean) {
// The row of the `contextToolbar` button in a list, as a list has no toolbar of its own. It
// replaces the main row, so it repeats the indentation and the moves, used most in a list.
listToolbar: [
- "outdent", "indent", "moveBlockUp", "moveBlockDown",
+ "outdent", "indent", "moveBlockUp", "moveBlockDown", ...getSortSelectionItems(),
"|",
"listTypeMenu", "listStartAt", "listReversed"
],
@@ -190,6 +191,7 @@ export function buildClassicToolbar(multilineToolbar: boolean, aiAssistant: bool
buildAlignmentToolbar(),
"outdent",
"indent",
+ ...getSortSelectionItems(),
"|",
"insertTemplate",
"markdownImport",
@@ -265,6 +267,7 @@ export function buildFloatingToolbar(aiAssistant: boolean) {
buildAlignmentToolbar(),
"outdent",
"indent",
+ ...getSortSelectionItems(),
"|",
"insertTemplate",
"markdownImport",
@@ -301,6 +304,11 @@ function getExtendedCodeBlockItems(): string[] {
return isExperimentalFeatureEnabled("extendedCodeBlocks") ? [ "extendedCodeBlock" ] : [];
}
+/** The button that sorts the selection, while its experimental feature is on. */
+function getSortSelectionItems(): string[] {
+ return isExperimentalFeatureEnabled("sortSelection") ? [ "sortSelection" ] : [];
+}
+
function buildAlignmentToolbar() {
return {
label: t("text-editor.toolbar-groups.alignment"),
diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.json
index a42d514898..167a781342 100644
--- a/apps/server/src/assets/help/help_content.json
+++ b/apps/server/src/assets/help/help_content.json
@@ -114,7 +114,7 @@
"_help_s3YCWHBfmYuM": "<h2>Choose the setup</h2><p><strong>Local only desktop/laptop</strong> - Allows a single instance on a desktop and will save the notes locally on that desktop.</p><ul><li><a class=\"reference-link\" href=\"#root/_help_poXkQfguuA0U\">Desktop Installation</a></li></ul><p><strong>Server with web only access</strong> - Installs the application on the server and allows access from any web browser on any device, including mobile.</p><ol><li><a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a></li><li><a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>&nbsp;(optional)</li><li><a class=\"reference-link\" href=\"#root/_help_yeEaYqosGLSh\">Third-party cloud hosting</a></li></ol><p><strong>Combination of server and desktop/laptop</strong> - Install the application on both a server, for web access and data synchronisation, and desktop instance(s). This allows all the data to be stored on the server and either accessed from the web browser, or the desktop application. The desktop application will sync and store the data locally so that it can be used when offline.</p><ol><li><a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a></li><li><a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>&nbsp;(optional)</li><li><a class=\"reference-link\" href=\"#root/_help_poXkQfguuA0U\">Desktop Installation</a></li><li><a class=\"reference-link\" href=\"#root/_help_cbkrhQjrkKrh\">Synchronization</a></li></ol>",
"_help_i6dbnitykE5D": "<h2>Inspiration for the name “Trilium”</h2><blockquote><p>Naming software is hard. I lived in Ontario when I first started the project and Trillium (the flower) is sort of a provincial logo, many institutions in Ontario are named \"Trillium [something]\". So I kept hearing/reading it almost everyday, I liked the sound of it and its nature motif, so I just reused it.</p><p><em>– Zadam (original Trilium maintainer)</em></p></blockquote><aside class=\"admonition note\"><p>Despite the fact that the Trillium flower has two “l\"s, the Trilium application only has one.</p></aside><h2>How do I create a folder?</h2><p>Trilium has no separate folder type: any note can have child notes, so any note can act as a folder. A note can hold its own content and have children at the same time, unlike a file system, which separates files from directories.</p><p>To organize notes into a folder:</p><ol><li>Create a note that acts as the folder, for example \"Projects\".</li><li>Right-click it in the <a class=\"reference-link\" href=\"#root/_help_oPVyFC7WL2Lp\">Note Tree</a> and select <em>Insert child note</em>, or hover over it and press the <span class=\"tn-icon bx bx-plus\"></span> button.</li><li>To move existing notes into it, drag them onto it in the tree.</li></ol><p>The children of a note are listed at the end of its content (see <a class=\"reference-link\" href=\"#root/_help_0ESUbbAxVnoK\">Note List</a>).</p><p>If you want the note to look like a folder, with no content of its own and only its children shown, make it a collection instead: right-click in the tree, select <em>Insert child note</em> → <em>Collection</em>, then choose <a class=\"reference-link\" href=\"#root/_help_8QqnMzx393bx\">Grid View</a> or <a class=\"reference-link\" href=\"#root/_help_mULW0Q3VojwY\">List View</a>. See <a class=\"reference-link\" href=\"#root/_help_GTwFsgaA0lCt\">Collections</a> for the other views, such as tables, boards and calendars.</p><h2>macOS support</h2><p>Originally, Trilium Notes considered the macOS build unsupported. TriliumNext commits to make the experience on macOS as good as possible.</p><p>if you find any platform-specific issues, feel free to <a href=\"#root/_help_wy8So3yZZlH9\">report them</a>.</p><h2>Translation / localisation support</h2><p>The original Trilium Notes application did not support multiple languages. Since we believe that internationalisation is a core part of an application, we have added support for it.</p><p>Contributions to translations are welcome.</p><h2>Multi-user support</h2><p>Common request is to allow multiple users collaborate, share notes etc. So far I'm resisting this because of these reasons:</p><ul><li>it's a huge feature, or rather a Pandora's box of collaboration features like user management, permissions, conflict resolution, real-time editing of a note by multiple people etc. This would be a huge amount of work. Trilium Notes is project made mostly by one person in free time and that's unlikely to change in the future.</li><li>given its size it would probably pivot the attention away from my main focus which is a personal note-taking</li><li>the assumption that only single person has access to the app simplifies many things, or just outright makes them possible. In multi-user app, our <a href=\"#root/_help_CdNpE2pqjmI6\">scripting</a>support would be a XSS security hole, while with the single user assumption it's an endless customizable tool.</li></ul><h2>How to open multiple documents in one Trilium instance</h2><p>This is normally not supported - one Trilium process can open only a single instance of a <a href=\"#root/_help_wX4HbRucYSDD\">database</a>. However, you can run two Trilium processes (from one installation), each connected to a separate document. To achieve this, you need to set a location for the <a href=\"#root/_help_tAassRL4RSQL\">data directory</a> in the <code>TRILIUM_DATA_DIR</code> environment variable and separate port on <code>TRILIUM_PORT</code> environment variable. How to do that depends on the platform, in Unix-based systems you can achieve that by running command such as this:</p><pre><code class=\"language-text-x-sh\">TRILIUM_DATA_DIR=/home/me/path/to/data/dir TRILIUM_PORT=12345 trilium </code></pre><p>You can save this command into a <code>.sh</code> script file or make an alias. Do this similarly for a second instance with different data directory and port.</p><h2>Can I use Dropbox / Google Drive / OneDrive to sync data across multiple computers.</h2><p>No.</p><p>These general purpose sync apps are not suitable to sync database files which are open and being worked on by another application. The result is that they will corrupt the database file, resulting in data loss and this message in the Trilium logs:</p><pre><code class=\"language-text-x-trilium-auto\">SqliteError: database disk image is malformed</code></pre><p>The only supported way to sync Trilium's data across the network is to use a <a href=\"#root/_help_cbkrhQjrkKrh\">sync/web server</a>.</p><h2>Why database instead of flat files?</h2><p>Trilium stores notes in a <a href=\"#root/_help_wX4HbRucYSDD\">database</a> which is an SQLite database. People often ask why doesn't Trilium rather use flat files for note storage - it's fair question since flat files are easily interoperable, work with SCM/git etc.</p><p>Short answer is that file systems are simply not powerful enough for what we want to achieve with Trilium. Using filesystem would mean fewer features with probably more problems.</p><p>More detailed answer:</p><ul><li><a href=\"#root/_help_IakOLONlIfGI\">clones</a> are what you might call \"hard directory link\" in filesystem lingo, but this concept is not implemented in any filesystem</li><li>filesystems make a distinction between directory and file while there's intentionally no such difference in Trilium</li><li>files are stored in no particular order and user can't change this</li><li>Trilium allows storing note <a href=\"#root/_help_zEY4DaJG4YT5\">attributes</a> which could be represented in extended user attributes but their support differs greatly among different filesystems / operating systems</li><li>Trilium makes links / relations between different notes which can be quickly retrieved / navigated (e.g. for <a href=\"#root/_help_BCkXAVs63Ttv\">note map</a>). There's no such support in file systems which means these would have to be stored in some kind of side-car files (mini-databases).</li><li>Filesystems are generally not transactional. While this is not completely required for a note-taking application, having transactions make it way easier to keep notes and their metadata in predictable and consistent state.</li></ul><h2>Search-related Questions</h2><h3>Why does search sometimes find results with typos?</h3><p>Trilium uses a progressive search strategy that includes fuzzy matching when exact matches return fewer than 5 results. This finds notes despite minor typos in your search query. You can use fuzzy search operators (<code>~=</code> for fuzzy exact match and <code>~*</code> for fuzzy contains). See the&nbsp;<a class=\"reference-link\" href=\"#root/_help_eIg8jdvaoNNd\">Search</a>&nbsp;documentation for details.</p><h3>How can I search for notes when I'm not sure of the exact spelling?</h3><p>Use the fuzzy search operators:</p><ul><li><code>#title ~= \"projct\"</code> - finds notes with titles like \"project\" despite the typo</li><li><code>note.content ~* \"algoritm\"</code> - finds content containing \"algorithm\" or similar words</li></ul><h3>Why do some search results appear before others with lower scores?</h3><p>Trilium places exact matches before fuzzy matches. When you search for \"project\", notes containing exactly \"project\" appear before notes with variations like \"projects\" or \"projection\", regardless of other scoring factors.</p><h3>How can I make my searches faster?</h3><ol><li>Use the \"Fast search\" option to search only titles and attributes (not content)</li><li>Limit search scope using the \"Ancestor\" field</li><li>Set a result limit to prevent loading too many results</li><li>For large databases, consider archiving old notes to reduce search scope</li></ol>",
"_help_KSZ04uQ2D1St": "<p>One of the core features of Trilium is that it supports multiple types of notes, depending on the need.</p><h2>Creating a new note with a different type via the note tree</h2><p>The default note type in Trilium (e.g. when creating a new note) is&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>, since it's for general use.</p><p>To create a new note of a different type, head to the&nbsp;<a class=\"reference-link\" href=\"#root/_help_oPVyFC7WL2Lp\">Note Tree</a>&nbsp;and right click an existing note where to place the new one and select:</p><ul><li><em>Insert note after</em>, to put the new note underneath the one selected.</li><li><em>Insert child note</em>, to insert the note as a child of the selected note.</li></ul><p>The note types created less often,&nbsp;<a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a>,&nbsp;<a class=\"reference-link\" href=\"#root/_help_HcABDtFCkbFN\">Render Note</a>,&nbsp;<a class=\"reference-link\" href=\"#root/_help_1vHRoWCEjj0L\">Web View</a>&nbsp;and&nbsp;<a class=\"reference-link\" href=\"#root/_help_bdUJEHsAPYQR\">Note Map</a>, are in the <em>More</em> submenu.</p><p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types_image.png\"></p><h2>Creating a new note of a different type via add link or new tab</h2><ul><li>When adding a <a href=\"#root/_help_QEAPj01N5f7w\">link</a> in a&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;note, type the desired title of the new note and press Enter. Afterwards the type of the note will be asked.</li><li>Similarly, when creating a new tab, type the desired title and press Enter.</li></ul><p>The note type is chosen from the same menu as in the note tree, with its submenus (code languages, snippets, collections and the note types created less often) and its search box: type to narrow the list, then press <kbd>Enter</kbd> to create the first match. <kbd>Enter</kbd> right away creates a Text note.</p><h2>Changing the type of a note</h2><p>It is possible to change the type of a note after it has been created via&nbsp;<a class=\"reference-link\" href=\"#root/_help_8YBEPzcpUgxw\">Note menu</a>&nbsp;→ <em>Note type</em>. This feature can also be used to edit the <a href=\"#root/_help_4FahAwuGTAwC\">source of a note</a>.</p><aside class=\"admonition note\"><p>Note that it's generally a good idea to change the note type only if the note is empty</p></aside><h2>Supported note types</h2><p>The following note types are supported by Trilium:</p><figure class=\"table\"><table><thead><tr><th>Note Type</th><th>Description</th></tr></thead><tbody><tr><td><a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a></td><td>The default note type, which allows for rich text formatting, images, admonitions and right-to-left support.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a></td><td>Uses a mono-space font and can be used to store larger chunks of code or plain text than a text note, and has better syntax highlighting.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a></td><td>Stores the information about a search (the search text, criteria, etc.) for later use. Can be used for quick filtering of a large amount of notes, for example. The search can easily be triggered.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_iRwzGnHPzonm\">Relation Map</a></td><td>Allows easy creation of notes and relations between them. Can be used for mainly relational data such as a family tree.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_bdUJEHsAPYQR\">Note Map</a></td><td>Displays the relationships between the notes, whether via relations or their hierarchical structure.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_HcABDtFCkbFN\">Render Note</a></td><td>Used in&nbsp;<a class=\"reference-link\" href=\"#root/_help_CdNpE2pqjmI6\">Scripting</a>, it displays the HTML content of another note. This allows displaying any kind of content, provided there is a script behind it to generate it.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_GTwFsgaA0lCt\">Collections</a></td><td>Displays the children of the note either as a grid, a list, or for a more specialized case: a calendar.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> <br>Generally useful for easy reading of short notes.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a></td><td>Displays diagrams such as bar charts, flow charts, state diagrams, etc. Requires a bit of technical knowledge since the diagrams are written in a specialized format.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a></td><td>Allows easy drawing of sketches, diagrams, handwritten content. Uses the same technology behind <a href=\"https://excalidraw.com\">excalidraw.com</a>.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_1vHRoWCEjj0L\">Web View</a></td><td>Displays the content of an external web page, similar to a browser.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_gBbsAeiuUxI5\">Mind Map</a></td><td>Easy for brainstorming ideas, by placing them in a hierarchical layout.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_81SGnPGMk7Xc\">Geo Map</a></td><td>Displays the children of the note as a geographical map, one use-case would be to plan vacations. It even has basic support for tracks. Notes can also be created from it.</td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_W8vYD3Q1zjCR\">File</a></td><td>Represents an uploaded file such as PDFs, images, video or audio files.</td></tr></tbody></table></figure>",
- "_help_iPIMuisry3hd": "<p>The default note type in Trilium, text notes allow for rich formatting, tables, images, admonitions and a handful of other features.</p><h2>Formatting bars</h2><p>Most of the interaction with text notes is done via the built-in toolbars. Depending on preference, there are two different layouts:</p><ul><li>The <em>Floating toolbar</em> is hidden by default and only appears when needed. In this mode there are actually two different toolbars:<br><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/1_Text_image.png\" width=\"496\" height=\"91\"><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/2_Text_image.png\" width=\"812\" height=\"114\"></li><li>A toolbar that appears when text is selected. This provides text-level formatting such as bold, italic, text colors, inline code, etc.<br><em><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text_image.png\" width=\"1109\" height=\"124\"></em></li></ul><p>Fore more information see&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>.</p><h2>Features and formatting</h2><p>Here's a list of various features supported by text notes:</p><figure class=\"table\"><table><thead><tr><th>Dedicated article</th><th>Feature</th></tr></thead><tbody><tr><td><a class=\"reference-link\" href=\"#root/_help_Gr6xFaF6ioJ5\">General formatting</a></td><td><ul><li>Headings (section titles, paragraph)</li><li>Font size</li><li>Bold, italic, underline, strike-through</li><li>Superscript, subscript</li><li>Font color &amp; background color</li><li>Remove formatting</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_S6Xx8QIWTV66\">Lists</a></td><td><ul><li>Bulleted lists</li><li>Numbered lists</li><li>To-do lists</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_NwBbFdNZ9h7O\">Block quotes &amp; admonitions</a></td><td><ul><li>Block quotes</li><li>Admonitions</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a></td><td><ul><li>Basic tables</li><li>Merging cells</li><li>Styling tables and cells.</li><li>Table captions</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_UYuUB1ZekNQU\">Developer-specific formatting</a></td><td><ul><li>Inline code</li><li>Code blocks</li><li>Keyboard shortcuts</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_AgjCISero73a\">Footnotes</a></td><td><ul><li>Footnotes</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_mT0HEkOsz6i1\">Images</a></td><td><ul><li>Images</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_QEAPj01N5f7w\">Links</a></td><td><ul><li>External links</li><li>Internal Trilium links</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a></td><td><ul><li>Include note</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a></td><td><ul><li>Links to blocks of a note</li><li>Including blocks of a note</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a></td><td><ul><li>Symbols</li><li><a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a></li><li>Mermaid diagrams</li><li>Horizontal ruler</li><li>Page break</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_dEHYtoWWi8ct\">Other features</a></td><td><ul><li>Indentation<ul><li>Markdown import</li></ul></li><li><a class=\"reference-link\" href=\"#root/_help_2x0ZAX9ePtzV\">Cut to subnote</a></li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_gLt3vA97tMcp\">Premium features</a></td><td><ul><li><a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a></li><li><a class=\"reference-link\" href=\"#root/_help_KC1HB96bqqHX\">Templates</a></li><li><a class=\"reference-link\" href=\"#root/_help_5wZallV2Qo1t\">Format Painter</a></li></ul></td></tr></tbody></table></figure><h2>Read-Only vs. Editing Mode</h2><p>Text notes are usually opened in edit mode. However, they may open in read-only mode if the note is too big or the note is explicitly marked as read-only. For more information, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_CoFPLs3dRlXc\">Read-Only Notes</a>.</p><h2>Keyboard shortcuts</h2><p>There are numerous keyboard shortcuts to format the text without having to use the mouse. For a reference of all the key combinations, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_A9Oc6YKKc65v\">Keyboard Shortcuts</a>. In addition, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_QrtTYPmdd1qq\">Markdown-like formatting</a>&nbsp;as an alternative to the keyboard shortcuts.</p><h2>Content width</h2><p>For readability purposes on wider screens, the width of text notes is limited via a configurable option. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_t596jLvPrqkS\">Content width</a>&nbsp;for more information.</p><h2>Converting to a Markdown note</h2><p>Text notes can be converted to&nbsp;<a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a>&nbsp;notes. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_jludwdW7N4hg\">Converting between note types</a>.</p><h2>Technical details</h2><p>For the text editing functionality, Trilium uses a commercial product (with an open-source base) called&nbsp;<a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>. This brings the benefit of having a powerful WYSIWYG (What You See Is What You Get) editor.</p>",
+ "_help_iPIMuisry3hd": "<p>The default note type in Trilium, text notes allow for rich formatting, tables, images, admonitions and a handful of other features.</p><h2>Formatting bars</h2><p>Most of the interaction with text notes is done via the built-in toolbars. Depending on preference, there are two different layouts:</p><ul><li>The <em>Floating toolbar</em> is hidden by default and only appears when needed. In this mode there are actually two different toolbars:<br><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/1_Text_image.png\" width=\"496\" height=\"91\"><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/2_Text_image.png\" width=\"812\" height=\"114\"></li><li>A toolbar that appears when text is selected. This provides text-level formatting such as bold, italic, text colors, inline code, etc.<br><em><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text_image.png\" width=\"1109\" height=\"124\"></em></li></ul><p>Fore more information see&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>.</p><h2>Features and formatting</h2><p>Here's a list of various features supported by text notes:</p><figure class=\"table\"><table><thead><tr><th>Dedicated article</th><th>Feature</th></tr></thead><tbody><tr><td><a class=\"reference-link\" href=\"#root/_help_Gr6xFaF6ioJ5\">General formatting</a></td><td><ul><li>Headings (section titles, paragraph)</li><li>Font size</li><li>Bold, italic, underline, strike-through</li><li>Superscript, subscript</li><li>Font color &amp; background color</li><li>Remove formatting</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_S6Xx8QIWTV66\">Lists</a></td><td><ul><li>Bulleted lists</li><li>Numbered lists</li><li>To-do lists</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_NwBbFdNZ9h7O\">Block quotes &amp; admonitions</a></td><td><ul><li>Block quotes</li><li>Admonitions</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a></td><td><ul><li>Basic tables</li><li>Merging cells</li><li>Styling tables and cells.</li><li>Table captions</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_UYuUB1ZekNQU\">Developer-specific formatting</a></td><td><ul><li>Inline code</li><li>Code blocks</li><li>Keyboard shortcuts</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_AgjCISero73a\">Footnotes</a></td><td><ul><li>Footnotes</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_mT0HEkOsz6i1\">Images</a></td><td><ul><li>Images</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_QEAPj01N5f7w\">Links</a></td><td><ul><li>External links</li><li>Internal Trilium links</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a></td><td><ul><li>Include note</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a></td><td><ul><li>Links to blocks of a note</li><li>Including blocks of a note</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a></td><td><ul><li>Symbols</li><li><a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a></li><li>Mermaid diagrams</li><li>Horizontal ruler</li><li>Page break</li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_dEHYtoWWi8ct\">Other features</a></td><td><ul><li>Indentation<ul><li>Markdown import</li></ul></li><li><a class=\"reference-link\" href=\"#root/_help_2x0ZAX9ePtzV\">Cut to subnote</a></li><li><a class=\"reference-link\" href=\"#root/_help_0vgWgxQAWj4a\">Sorting</a></li></ul></td></tr><tr><td><a class=\"reference-link\" href=\"#root/_help_gLt3vA97tMcp\">Premium features</a></td><td><ul><li><a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a></li><li><a class=\"reference-link\" href=\"#root/_help_KC1HB96bqqHX\">Templates</a></li><li><a class=\"reference-link\" href=\"#root/_help_5wZallV2Qo1t\">Format Painter</a></li></ul></td></tr></tbody></table></figure><h2>Read-Only vs. Editing Mode</h2><p>Text notes are usually opened in edit mode. However, they may open in read-only mode if the note is too big or the note is explicitly marked as read-only. For more information, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_CoFPLs3dRlXc\">Read-Only Notes</a>.</p><h2>Keyboard shortcuts</h2><p>There are numerous keyboard shortcuts to format the text without having to use the mouse. For a reference of all the key combinations, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_A9Oc6YKKc65v\">Keyboard Shortcuts</a>. In addition, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_QrtTYPmdd1qq\">Markdown-like formatting</a>&nbsp;as an alternative to the keyboard shortcuts.</p><h2>Content width</h2><p>For readability purposes on wider screens, the width of text notes is limited via a configurable option. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_t596jLvPrqkS\">Content width</a>&nbsp;for more information.</p><h2>Converting to a Markdown note</h2><p>Text notes can be converted to&nbsp;<a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a>&nbsp;notes. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_jludwdW7N4hg\">Converting between note types</a>.</p><h2>Technical details</h2><p>For the text editing functionality, Trilium uses a commercial product (with an open-source base) called&nbsp;<a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>. This brings the benefit of having a powerful WYSIWYG (What You See Is What You Get) editor.</p>",
"_help_oSuaNgyyKnhu": "<aside class=\"admonition note\"><p>This feature used to be called <em>Bookmarks</em> (as it is the official name in the editor we are using), but in order not to collide with the concept of&nbsp;<a class=\"reference-link\" href=\"#root/_help_u3YFHC9tQlpm\">Bookmarks</a>, we have renamed it to <em>Anchors.</em></p></aside><p>Anchors allows creating <a href=\"#root/_help_QEAPj01N5f7w\">links</a> to a certain part of a note, such as referencing a particular heading or section within a note.</p><p>This feature was introduced in TriliumNext v0.94.0 and augmented in v0.103.0 to support linking across notes.</p><h2>Interaction</h2><ul><li>To create a anchor:<ul><li>Place the cursor at the desired position where to place the anchor.</li><li>Look for the&nbsp;<span class=\"tn-icon bx bx-plus\"></span> button in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, and then press the&nbsp;<span class=\"tn-icon cke cke-bookmark\"></span> button.</li><li>Alternatively, use&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>&nbsp;and look for <em>anchor</em>.</li></ul></li><li>To place a link to a anchor:<ul><li>Place the cursor at the desired position of the link.</li><li>From the <a href=\"#root/_help_QEAPj01N5f7w\">link</a> pane, select the <em>Anchors</em> section and select the desired anchor.</li></ul></li></ul><h2>Linking across notes</h2><p>Trilium v0.103.0 introduces cross-note Anchors, which makes it possible to create&nbsp;<a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>&nbsp;which point to a specific anchor in that document.</p><h3>Compatibility with documents from previous versions</h3><p>For notes created prior to Trilium v0.103.0, you might notice that the Anchors might not be identified. This limitation is intentional in order not to have to re-process all the notes, looking for anchors.</p><p>To fix this, simply go that note and make any change (e.g. inserting a space), this will trigger the recalculation of the links.</p><h3>Linking to anchors through the <em>Add link</em> dialog</h3><ol><li>Create an anchor in the target note using the same process as described above.</li><li>In another note, press <kbd>Ctrl</kbd>+<kbd>L</kbd> to insert an internal link. Select the target note containing Anchors.</li><li>If the target note contains Anchors, a section will appear underneath the note selector with the list of Anchors.</li><li>Add the link normally.</li></ol><p>Clicking on a reference link pointing to a anchor will automatically scroll to the desired section.</p><h3>Linking to anchors through the bookmark toolbar</h3><ol><li>Create an anchor in the target note using the same process as described above.</li><li>Click on the anchor to reveal the anchor's floating toolbar.</li><li>Click on the <span class=\"tn-icon cke cke-trilium-copy\"></span> <em>Copy anchor reference link</em> button.</li><li>Go to the note where to insert the link and press <kbd>Ctrl</kbd>+<kbd>V</kbd>.</li></ol><aside class=\"admonition note\"><p>Use this method only to insert&nbsp;<a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>&nbsp;between two documents. To link to an anchor on the same note, use the <em>Insert link</em> dialog (<kbd>Ctrl</kbd>+<kbd>K</kbd>) and select the <em>Anchors</em> item instead.</p></aside>",
"_help_oI7GoyilXXAr": "<h2>Automatic replacements</h2><p>As you type in a text note, certain character sequences are replaced with the typographic symbol they represent. Typing <code>(c)</code> gives you <code>©</code>, <code>...</code> gives you <code>…</code>, and <code>\"quote\"</code> gives you <code>“quote”</code>.</p><p>These replacements are not applied inside code blocks or inline code, and pasted text is never affected, only text you type. If you have pasted a code snippet, or written one inside a code block, its characters are left exactly as they are.</p><h3>Undoing a replacement</h3><p>Once an automatic replacement takes place, it can be undone by:</p><ul><li>Pressing <kbd>Backspace</kbd> immediately after a replacement undoes it and restores what you typed.<ul><li>Note that this consumes the undo, so a further <kbd>Ctrl</kbd>+<kbd>Z</kbd> might delete your typed text.</li><li>Pressing <kbd>Space</kbd> or changing the cursor position disables this functionality.</li></ul></li><li>Pressing <kbd>Ctrl</kbd>+<kbd>Z</kbd>, which works even after pressing space.</li></ul><h3>Replacement groups &amp; configuration</h3><p>Each group can be turned off in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Text notes</em> → <em>Automatic replacements</em>.</p><figure class=\"table\"><table><thead><tr><th>Group</th><th>What it replaces</th></tr></thead><tbody><tr><td>Punctuation</td><td><code>...</code> with an ellipsis (<code>…</code>), and <code>--</code> and <code>---</code> <em>surrounded by spaces</em> with an en dash (<code>–</code>) and an em dash (<code>—</code>)</td></tr><tr><td>Mathematical symbols</td><td>fractions such as <code>1/2</code> with <code>½</code>, and the operators <code>&lt;=</code>, <code>&gt;=</code>, <code>!=</code>, <code>&lt;-</code> and <code>-&gt;</code> with <code>≤</code>, <code>≥</code>, <code>≠</code>, <code>←</code> and <code>→</code></td></tr><tr><td>Copyright and trademark</td><td><code>(c)</code>, <code>(r)</code> and <code>(tm)</code> with <code>©</code>, <code>®</code> and <code>™</code></td></tr><tr><td>Quotation marks</td><td>straight quotes with typographic ones — see below</td></tr></tbody></table></figure><h2>Quotation marks</h2><p>Quotation marks are configured separately from the rest, with one setting for the <strong>double</strong> quote key and one for the <strong>single</strong> quote key, because which pair belongs on which key differs between conventions: British typography traditionally sets a quotation in <code>‘…’</code> where American sets it in <code>“…”</code>.</p><p>Each offers:</p><ul><li><em>Based on the note's content language</em> (the default) — English gives <code>“quote”</code>, German <code>„quote“</code>, French <code>« quote »</code>, Japanese <code>「quote」</code>. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_veGu4faJErEM\">Content language &amp; Right-to-left support</a>&nbsp;for how a note's language is decided.</li><li><em>Disabled,</em> straight quotes stay straight.</li><li>A specific pair_:_ <code>“…”</code>, <code>‘…’</code>, <code>„…“</code>, <code>„…”</code>, <code>«…»</code>, <code>« … »</code>, <code>‹…›</code>, <code>「…」</code>, <code>『…』</code>. Choosing one applies it to every note, regardless of its content language.</li></ul><h2>Custom replacements</h2><p>You can add your own under&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Text notes</em> → <em>Automatic replacements</em> → <em>Custom replacements</em>. Type the text to replace and the replacement, then press Enter. Existing ones are shown as chips and removed with the × on each.</p><p>A custom replacement is applied when the text is typed as a whole word and followed by a space, so longer words that begin with it are left alone — a <code>TN</code> replacement does not rewrite the end of <code>BTN</code>, and <code>TNT</code> can still be typed.</p><p>Capitalization follows what you type, unless the replacement has capitals of its own:</p><figure class=\"table\"><table><thead><tr><th><strong>Replacement you defined</strong></th><th><strong>You type</strong></th><th><strong>You get</strong></th></tr></thead><tbody><tr><td><code>teh</code> → <code>the</code></td><td><code>teh</code> / <code>Teh</code> / <code>TEH</code></td><td><code>the</code> / <code>The</code> / <code>THE</code></td></tr><tr><td><code>TN</code> → <code>Trilium Notes</code></td><td><code>TN</code> or <code>tn</code></td><td><code>Trilium Notes</code> (unchanged, it has capitals)</td></tr></tbody></table></figure><p>Of note:</p><ul><li>The text to replace is matched literally; it is not a pattern.</li><li>Typing a \"text to replace\" that already exists in the list of replacements will update the existing one instead. It's not possible to have multiple replacements for the same text.</li><li>The same “text to replace” with different capitalization (e.g. <code>TN</code> and <code>tn</code> co-existing) doesn't work because it would interfere with the capitalization rules above.</li></ul><h2>Characters that only look replaced (ligatures)</h2><p>If you see <code>!=</code> displayed as <code>≠</code> or <code>-&gt;</code> as <code>→</code> inside a code block, that is not a replacement since replacements never run there (unless a code block is applied to an existing text). It is a <em>font ligature</em>: the default monospace font draws certain character pairs as a single symbol. The underlying text is unchanged, and copying it out gives you back <code>!=</code> and <code>-&gt;</code>.</p><p>This can be turned off with&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a><em>→ Appearance → Fonts → Programming ligatures.</em></p>",
"_help_NwBbFdNZ9h7O": "<h2>Block quotes</h2><p>As the name suggests, block quotes can be useful to cite one or more paragraphs.</p><p>To create a block quote, press&nbsp;<span class=\"tn-icon cke cke-quote\"></span> from the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>. It's also possible to type <kbd>&gt;</kbd>, followed by a space to create one (but only if the cursor is at the beginning of a line).</p><p>Inside the quote block, other block items can be inserted such as tables, images, or even other block quotes or admonitions.</p><h2>Admonitions</h2><p>Admonitions are a way to highlight information to the reader. Other names for it include <em>call-outs</em> and <em>info/warning/alert boxes</em>.</p><figure class=\"image image-style-align-center\"><img style=\"aspect-ratio:959/547;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Block%20quotes%20%26%20admonitions_image.png\" width=\"959\" height=\"547\"></figure><p>From a functional point of view, admonitions act very similarly to a block quote, just with different styling. This includes the ability to insert other elements in it such as headings, tables, images, etc.</p><h3>Inserting a new admonition</h3><p>In the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:</p><p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Block%20quotes%20%26%20admonitions_image.png\"></p><p>It's possible to insert an admonition simply by typing:</p><ul><li><code>!!! note</code></li><li><code>!!! tip</code></li><li><code>!!! important</code></li><li><code>!!! caution</code></li><li><code>!!! warning</code></li></ul><p>In addition to that, it's also possible to type <code>!!!</code>&nbsp; followed by any text, case in which a default admonition type will appear (note) with the entered text inside it.</p><h3>Interaction</h3><p>By design, admonitions act very similar to block quotes.</p><ul><li>Selecting a text and pressing the admonition button will turn that text into an admonition.</li><li>If selecting multiple admonitions, pressing the admonition button will automatically merge them into one.</li></ul><p>Inside an admonition:</p><ul><li>Pressing <kbd>Backspace</kbd> while the admonition is empty will remove it.</li><li>Pressing <kbd>Enter</kbd> will start a new paragraph. Pressing it twice will exit out of the admonition.</li><li>Headings and other block content including tables can be inserted inside the admonition.</li></ul><h3>Types of admonitions</h3><p>There are currently five types of admonitions: <em>Note</em>, <em>Tip</em>, <em>Important</em>, <em>Caution</em>, <em>Warning</em>.</p><p>These types were inspired by GitHub's support for this feature and there are currently no plans for adjusting it or allowing the user to customize them.</p><h3>Markdown support</h3><p>See&nbsp;<a class=\"reference-link\" href=\"#root/_help_rJ9grSgoExl9\">Supported syntax</a>.</p>",
@@ -143,13 +143,14 @@
"_help_3IDVtesTQ8ds": "<p>An external link is a standard web link targeting for example a website. For example, <a href=\"https://en.wikipedia.org/wiki/South_China_Sea\">https://en.wikipedia.org/wiki/South_China_Sea</a> is an external link to a Wikipedia page.</p><p>To create a link without a custom text:</p><ul><li>Press&nbsp;<span class=\"tn-icon cke cke-link\"></span> in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:<ul><li>A popup will appear, type or paste the URL in the box.</li><li>Press <kbd>Enter</kbd> or the check mark icon to confirm.</li></ul></li><li>Alternatively, press <kbd>Ctrl</kbd>+<kbd>K</kbd> to trigger the aforementioned popup.</li><li>A simpler way is to paste the raw link and press space to turn it automatically into a link.</li><li>Since v0.107.0, the <em>Add link</em> dialog of <a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a> (<kbd>Ctrl</kbd>+<kbd>L</kbd> or the <span class=\"tn-icon cke cke-trilium\"></span> button) creates external links as well. Select <em>Web link</em> at the top of the dialog, type or paste the address, and optionally a <em>Link title</em>; without one, the link shows its address. An address without a scheme, such as <code>example.com</code>, gets <code>https://</code>. A URL pasted into the <em>Note</em> field, or picked from its search, switches the dialog to <em>Web link</em>. The dialog also opens on <em>Web link</em> when the selected text is a URL.</li></ul><p>To create a link with a custom text:</p><ul><li>First, type and select the text which will be turned into a link.</li><li>Follow the previous steps to open the link interface (via the formatting toolbar, or <kbd>Ctrl</kbd>+<kbd>K</kbd>).</li><li>Alternatively, simply paste (<kbd>Ctrl</kbd>+<kbd>V</kbd>) over the selected text to turn it into a link.</li></ul><p>Once a link is inserted:</p><ul><li>The text inside the link can be changed if needed but the link itself will remain.</li><li>To modify the link, click on the link to display the popup and press the&nbsp;<span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button. Since v0.107.0, it opens the <em>Edit link</em> dialog, filled with the link's address and text, as do placing the cursor inside the link and pressing <kbd>Ctrl</kbd>+<kbd>L</kbd> or the <span class=\"tn-icon cke cke-trilium\"></span> button. <em>Save link</em> changes the whole link, its text included, and the dialog can also turn it into a link to a note.</li><li>To remove a link, click on it and press the&nbsp;<span class=\"tn-icon cke cke-unlink\"></span> <em>Unlink</em> button.</li></ul><p>You can follow external link by either double clicking (will open new tab/window) it or right clicking on them and choosing \"Open in new tab\".</p>",
"_help_hrZ1D00cLbal": "<p>Internal links are links to other notes within Trilium.</p><p>You can open an internal link by clicking it. You can also see a read-only preview of an internal link's contents by hovering over it.</p><h2>Inserting internal links</h2><p>Internal links can be created at the current position in a text note by:</p><ol><li>Pressing <kbd>Ctrl</kbd> + <kbd>L</kbd> or the&nbsp;<span class=\"tn-icon cke cke-trilium\"></span> button underneath the&nbsp;<span class=\"tn-icon cke cke-plus\"></span> menu in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>.</li><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>&nbsp;(today's day note, or the top level, when 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, chosen with the <em>Mirror the note's title</em> switch of the dialog, which is on by default:</p><ol><li>With the switch on, the link mirrors the note's title.<ol><li>This is sometimes also called \"reference link\".</li><li>The title of this link cannot be changed. Instead, it will always show the current title of the linked note.</li><li>The icon of the linked note will also be displayed.</li><li>If the linked note is deleted, the link keeps the last title it showed, in red and with a <span class=\"tn-icon bx bx-x\"></span> icon instead of the note icon. Clicking it while editing opens the <em>Fix link</em> dialog, which searches for that title; picking a note, or creating a new one, replaces the link with one to that note.</li></ol></li><li>With the switch off, the link has a title of its own, typed in the <em>Link title</em> field.<ol><li>This will create a traditional hyperlink, where the text of the link can be different from the note title.</li></ol></li></ol><p>Since v0.107.0, to change a link whose title does not mirror the note's, click it and press the <span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button in its popup, or place the cursor inside it and press <kbd>Ctrl</kbd> + <kbd>L</kbd> or the <span class=\"tn-icon cke cke-trilium\"></span> button. The <em>Edit link</em> dialog opens on the linked note, with its anchor and the link's text; <em>Save link</em> changes the whole link. Turning <em>Mirror the note's title</em> on there turns it into a link that mirrors the title.</p><h2>In-place linking</h2><p>You can also insert internal links “inline” by using the <code>@</code> symbol:</p><ol><li>Type <code>@</code> in a text note, which will open the note search menu.</li><li>Search for the desired note's title by typing a few characters. Use <kbd>Up</kbd> and <kbd>Down</kbd> to select the correct note, and press <kbd>Enter</kbd> or <kbd>Tab</kbd> to create the link. It's also possible to create new notes with this method by typing a non-existing note title and selecting <em>Create note</em> or <em>Create child note</em>, as described above.</li></ol><h2>Pasting internal links</h2><p>You can also insert internal links by copying a note from the note tree.</p><ol><li>In the&nbsp;<a class=\"reference-link\" href=\"#root/_help_oPVyFC7WL2Lp\">Note Tree</a>, select a note and press <kbd>Ctrl</kbd> + <kbd>C</kbd>.</li><li>In a text note, paste the link by pressing <kbd>Ctrl</kbd> + <kbd>V</kbd>.</li></ol>",
"_help_wfGXLmm7x27z": "<p>A link points from one note to another; a <em>backlink</em> is that same connection seen from the other end: the list of notes that refer to the current one.</p><p>Backlinks are maintained automatically and are read-only from this side. A backlink disappears when the note that created it removes the link; it cannot be deleted from the note being pointed at.</p><h2>What counts as a backlink</h2><p>Any&nbsp;<a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>&nbsp;pointing at the current note, which covers two rather different cases:</p><ul><li>Relations that Trilium maintains on your behalf.<ul><li>The most common is <code>internalLink</code>, created whenever a note refers to another one through&nbsp;<a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>&nbsp;in its text.</li><li>Embedded images (<code>imageLink</code>), relation map connections (<code>relationMapLink</code>) and note inclusions (<code>includeNoteLink</code>) work the same way.</li></ul></li><li>Relations you define yourself.<ul><li>If another note has <code>~author</code> pointing at the current note, that note is listed here as well.</li></ul></li></ul><p>Relations coming from a&nbsp;<a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a>&nbsp;are excluded, since a search stores an <code>ancestor</code> relation that would otherwise list every one of its results as a backlink.</p><aside class=\"admonition note\"><p>Only some note types have their content scanned for links:&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>,&nbsp;<a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a>,&nbsp;<a class=\"reference-link\" href=\"#root/_help_iRwzGnHPzonm\">Relation Map</a>&nbsp;and&nbsp;<a class=\"reference-link\" href=\"#root/_help_GBBMSlVSOIGP\">AI</a>&nbsp;chats. A link written inside a&nbsp;<a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a>&nbsp;note is not registered and will not appear as a backlink on the target note. A relation set manually on a code note does still count.</p></aside><h2>How entries are displayed</h2><p>Each entry names the note the reference comes from, followed by one of:</p><ul><li><strong>An excerpt</strong> of the surrounding content, with the link itself highlighted. This is available for&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;notes and for&nbsp;<a class=\"reference-link\" href=\"#root/_help_GBBMSlVSOIGP\">AI</a>&nbsp;chat notes. Roughly 200 characters of context are quoted around the link, trimmed with an ellipsis where the surrounding text is longer, and images are left out.</li><li><strong>The name of the relation</strong>, for every other note type where the source cannot be quoted. This is the case for&nbsp;<a class=\"reference-link\" href=\"#root/_help_iRwzGnHPzonm\">Relation Map</a>&nbsp;notes and for any note carrying a relation you defined yourself.</li></ul><p>A note is listed once per reference it makes, so a note that links to the current one three times occupies three rows.</p><p>Of note:</p><ul><li>For AI chat notes, only the assistant's own prose is quoted. A chat that reached the note purely through tool calls has nothing to quote and is listed by relation name instead.</li><li>Excerpts are only generated for roughly the first 50 sources. On a heavily referenced note, the remaining entries fall back to showing the relation name.</li></ul><h2>Where backlinks are shown</h2><ul><li>In the&nbsp;<a class=\"reference-link\" href=\"#root/_help_KRlZFoIH0j6p\">Connections tab</a>&nbsp;of the&nbsp;<a class=\"reference-link\" href=\"#root/_help_RnaPdbciOfeq\">Right Sidebar</a>, as a dedicated section.</li><li>As a badge in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a>&nbsp;showing the number of backlinks. The badge only appears when the note is being read normally (not in a revision or attachment view) and when there is at least one backlink; pressing it opens the section above.</li><li>In&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, as a button with a link icon in the header of the popup, under the same conditions; its tooltip gives the number of backlinks. Pressing a backlink opens that note in the popup.</li><li>Incoming links are also drawn on the link map, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_BCkXAVs63Ttv\">Note Map (Link map, Tree map)</a>.</li></ul>",
- "_help_S6Xx8QIWTV66": "<p>There are three types of lists supported by text notes:</p><ul><li><span class=\"tn-icon cke cke-bulleted-list\"></span>&nbsp;Bulleted lists (also known as unordered lists).</li><li><span class=\"tn-icon cke cke-numbered-list\"></span>&nbsp;Numbered lists (or ordered lists).</li><li><span class=\"tn-icon cke cke-todo-list\"></span>&nbsp;To-do lists</li></ul><p>For bulleted and numbered lists, it's possible to configure an alternative marker such as squares or Roman numbering by pressing the&nbsp;<span class=\"tn-icon cke cke-dropdown-arrow\"></span> icon. For numbered lists, it's also possible to specify the number to start at or whether to count in reverse order. On the <a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, these are in the row of the <em>List ›</em> button, which shows while the cursor is in a list; its <em>List type</em> button also turns the list into another kind, to-do lists included.</p><h2>Keyboard interaction</h2><ul><li>To create a new list:<ul><li>Bulleted list: Start a line with <code>*</code> or <code>-</code> followed by a space;</li><li>Numbered list: Start a line with <code>1.</code> or <code>1)</code> followed by a space;</li><li>To-do list: Start a line with <code>- [ ]</code> for an unchecked item or <code>[x]</code> for a checked item.</li></ul></li><li>To create a new item in the list, press <kbd>Enter</kbd>.</li><li>To create a blank line within a list item, press <kbd>Shift</kbd>+<kbd>Enter</kbd>.</li><li>To exit out of the list, press <kbd>Enter</kbd> twice.</li><li>To merge two lists, simply delete the gap between them.</li><li>To create nested lists, simply use the&nbsp;<span class=\"tn-icon cke cke-indent\"></span> button (see <em>Indentation</em> in&nbsp;<a class=\"reference-link\" href=\"#root/_help_dEHYtoWWi8ct\">Other features</a>) or the <kbd>Tab</kbd> key. To decrease the nesting level for the current element, press <kbd>Shift</kbd>+<kbd>Tab</kbd>.</li></ul><h2>Headings, code blocks within lists</h2><p>It possible to add content-level blocks such as headings, code blocks, tables within lists, as follows:</p><figure class=\"table\"><table><tbody><tr><td>1</td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Lists_image.jpg\"></td><td>First, create a list.</td></tr><tr><td>2</td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/4_Lists_image.jpg\"></td><td>Press Enter to create a new list item.</td></tr><tr><td>3</td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Lists_image.jpg\"></td><td>Press Backspace to get rid of the bullet point. Notice the cursor position.</td></tr><tr><td>4</td><td><img class=\"image_resized\" style=\"aspect-ratio:676/112;width:98.29%;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/5_Lists_image.jpg\" width=\"676\" height=\"112\"></td><td>At this point, insert any desired block-level item such as a code block.</td></tr><tr><td>5</td><td><img class=\"image_resized\" style=\"aspect-ratio:675/129;width:94.22%;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_Lists_image.jpg\" width=\"675\" height=\"129\"></td><td>To continue with a new bullet point, press Enter until the cursor moves to a new blank position.</td></tr><tr><td>6</td><td><img class=\"image_resized\" style=\"aspect-ratio:675/129;width:100%;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Lists_image.jpg\" width=\"675\" height=\"129\"></td><td>Press Enter once more to create the new bullet.</td></tr></tbody></table></figure><p>The same principle applies to all three list types (bullet, numbered and to-do).</p><h2>Alignment</h2><p>A list item can be centered or aligned to the right, either with the text alignment button in the formatting toolbar or by aligning the <a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a> cell that contains the list. The bullet, number or checkbox then moves together with the text of the item.</p><h2>To-do lists</h2><p>See&nbsp;<a class=\"reference-link\" href=\"#root/_help_fASfBrYnquKU\">To-do Lists</a>.</p><h2>Collapsible lists</h2><p>Starting with Trilium v0.104.0, it is possible to collapse nested list items. This applies to bullet lists, numbered lists as well as to-do lists.</p><p>To collapse or expand a list item that has nested sub-items:</p><ul><li>Using the mouse, move the cursor over the list item and an arrow will appear to its left. Clicking it will toggle between collapsed and expanded.</li><li>For bullet lists and numbered lists, it's also possible to click directly on the marker (e.g. the bullet or the number) instead of on the arrow to collapse or expand it. This won't work for to-do lists since this would toggle the to-do instead.</li><li>Press <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Enter</kbd> which will toggle the collapse/expand state for the item at the cursor position.</li></ul><p>Of note:</p><ul><li>Collapsed items always show the arrow to indicate its state.</li><li>The collapsed state is saved at note level and synced across instances, which means that it will restore after a refresh or reopening of the application.</li><li>The collapsed state is also persisted in&nbsp;<a class=\"reference-link\" href=\"#root/_help_mHbBMPDPkVV5\">Import &amp; Export</a>, but only for the HTML format. Markdown exports will not preserve the collapse state.</li><li>Collapsible bullets only exist in the context of editable text notes. Read-only lists will always be fully expanded.</li><li>The list items will auto-expand on edit to avoid typing in a hidden area.</li></ul>",
+ "_help_S6Xx8QIWTV66": "<p>There are three types of lists supported by text notes:</p><ul><li><span class=\"tn-icon cke cke-bulleted-list\"></span>&nbsp;Bulleted lists (also known as unordered lists).</li><li><span class=\"tn-icon cke cke-numbered-list\"></span>&nbsp;Numbered lists (or ordered lists).</li><li><span class=\"tn-icon cke cke-todo-list\"></span>&nbsp;To-do lists</li></ul><p>For bulleted and numbered lists, it's possible to configure an alternative marker such as squares or Roman numbering by pressing the&nbsp;<span class=\"tn-icon cke cke-dropdown-arrow\"></span> icon. For numbered lists, it's also possible to specify the number to start at or whether to count in reverse order. On the <a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, these are in the row of the <em>List ›</em> button, which shows while the cursor is in a list; its <em>List type</em> button also turns the list into another kind, to-do lists included.</p><h2>Keyboard interaction</h2><ul><li>To create a new list:<ul><li>Bulleted list: Start a line with <code>*</code> or <code>-</code> followed by a space;</li><li>Numbered list: Start a line with <code>1.</code> or <code>1)</code> followed by a space;</li><li>To-do list: Start a line with <code>- [ ]</code> for an unchecked item or <code>[x]</code> for a checked item.</li></ul></li><li>To create a new item in the list, press <kbd>Enter</kbd>.</li><li>To create a blank line within a list item, press <kbd>Shift</kbd>+<kbd>Enter</kbd>.</li><li>To exit out of the list, press <kbd>Enter</kbd> twice.</li><li>To merge two lists, simply delete the gap between them.</li><li>To create nested lists, simply use the&nbsp;<span class=\"tn-icon cke cke-indent\"></span> button (see <em>Indentation</em> in&nbsp;<a class=\"reference-link\" href=\"#root/_help_dEHYtoWWi8ct\">Other features</a>) or the <kbd>Tab</kbd> key. To decrease the nesting level for the current element, press <kbd>Shift</kbd>+<kbd>Tab</kbd>.</li></ul><h2>Headings, code blocks within lists</h2><p>It possible to add content-level blocks such as headings, code blocks, tables within lists, as follows:</p><figure class=\"table\"><table><tbody><tr><td>1</td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Lists_image.jpg\"></td><td>First, create a list.</td></tr><tr><td>2</td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/4_Lists_image.jpg\"></td><td>Press Enter to create a new list item.</td></tr><tr><td>3</td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Lists_image.jpg\"></td><td>Press Backspace to get rid of the bullet point. Notice the cursor position.</td></tr><tr><td>4</td><td><img class=\"image_resized\" style=\"aspect-ratio:676/112;width:98.29%;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/5_Lists_image.jpg\" width=\"676\" height=\"112\"></td><td>At this point, insert any desired block-level item such as a code block.</td></tr><tr><td>5</td><td><img class=\"image_resized\" style=\"aspect-ratio:675/129;width:94.22%;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_Lists_image.jpg\" width=\"675\" height=\"129\"></td><td>To continue with a new bullet point, press Enter until the cursor moves to a new blank position.</td></tr><tr><td>6</td><td><img class=\"image_resized\" style=\"aspect-ratio:675/129;width:100%;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Lists_image.jpg\" width=\"675\" height=\"129\"></td><td>Press Enter once more to create the new bullet.</td></tr></tbody></table></figure><p>The same principle applies to all three list types (bullet, numbered and to-do).</p><h2>Sorting</h2><p>The items of a list can be sorted, nested items moving with the item they belong to. This is experimental, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_0vgWgxQAWj4a\">Sorting</a>.</p><h2>Alignment</h2><p>A list item can be centered or aligned to the right, either with the text alignment button in the formatting toolbar or by aligning the <a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a> cell that contains the list. The bullet, number or checkbox then moves together with the text of the item.</p><h2>To-do lists</h2><p>See&nbsp;<a class=\"reference-link\" href=\"#root/_help_fASfBrYnquKU\">To-do Lists</a>.</p><h2>Collapsible lists</h2><p>Starting with Trilium v0.104.0, it is possible to collapse nested list items. This applies to bullet lists, numbered lists as well as to-do lists.</p><p>To collapse or expand a list item that has nested sub-items:</p><ul><li>Using the mouse, move the cursor over the list item and an arrow will appear to its left. Clicking it will toggle between collapsed and expanded.</li><li>For bullet lists and numbered lists, it's also possible to click directly on the marker (e.g. the bullet or the number) instead of on the arrow to collapse or expand it. This won't work for to-do lists since this would toggle the to-do instead.</li><li>Press <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Enter</kbd> which will toggle the collapse/expand state for the item at the cursor position.</li></ul><p>Of note:</p><ul><li>Collapsed items always show the arrow to indicate its state.</li><li>The collapsed state is saved at note level and synced across instances, which means that it will restore after a refresh or reopening of the application.</li><li>The collapsed state is also persisted in&nbsp;<a class=\"reference-link\" href=\"#root/_help_mHbBMPDPkVV5\">Import &amp; Export</a>, but only for the HTML format. Markdown exports will not preserve the collapse state.</li><li>Collapsible bullets only exist in the context of editable text notes. Read-only lists will always be fully expanded.</li><li>The list items will auto-expand on edit to avoid typing in a hidden area.</li></ul>",
"_help_QrtTYPmdd1qq": "<p>Markdown-like formatting allows inserting some basic formatting by typing the Markdown equivalent. Note that this does not mean that&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;notes supports Markdown, these are just some convenience shortcuts.</p><p>To import more complex formatting into text notes, consider using the <a href=\"#root/_help_dEHYtoWWi8ct\"><em>Import from Markdown</em></a> function. For fully-fleged Markdown notes imports, consider using the dedicated <a href=\"#root/_help_Oau6X9rCuegd\">import</a> function.</p><ul><li>For <a href=\"#root/_help_Gr6xFaF6ioJ5\">headings:</a><ul><li><code>##</code> for Heading 2 (the first-level heading is reserved for the note title).</li><li><code>###</code> for Heading 3</li><li><code>####</code> for Heading 4</li><li><code>#####</code> for Heading 5</li><li><code>######</code> for Heading 6</li></ul></li><li>For&nbsp;<a class=\"reference-link\" href=\"#root/_help_Gr6xFaF6ioJ5\">General formatting</a>:<ul><li><strong>Bold</strong>: Type <code>**text**</code> or <code>__text__</code></li><li><em>Italic</em>: Type <code>*text*</code> or <code>_text_</code></li><li><del>Strikethrough</del>: Type <code>~~text~~</code></li></ul></li><li>For&nbsp;<a class=\"reference-link\" href=\"#root/_help_S6Xx8QIWTV66\">Lists</a>:<ul><li>Bulleted list: Start a line with <code>*</code> or <code>-</code> followed by a space;</li><li>Numbered list: Start a line with <code>1.</code> or <code>1)</code> followed by a space;</li><li>To-do list: Start a line with <code>[ ]</code> for an unchecked item or <code>[x]</code> for a checked item.</li></ul></li><li>For <a href=\"#root/_help_NwBbFdNZ9h7O\">block quotes</a>, press <code>&gt;</code>, followed by a space.</li><li>For&nbsp;<a class=\"reference-link\" href=\"#root/_help_QxEyIjRBizuC\">Code blocks</a>, type <code>```</code>.</li><li>For a <a href=\"#root/_help_dEHYtoWWi8ct\">horizontal line</a>, type <code>---</code>.</li><li>For <a href=\"#root/_help_NwBbFdNZ9h7O\">admonitions</a>:<ul><li><code>!!! note</code></li><li><code>!!! tip</code></li><li><code>!!! important</code></li><li><code>!!! caution</code></li><li><code>!!! warning</code></li><li>Starting any other text with <code>!!!</code> will insert a note admonition with the text inside of it.</li></ul></li><li>For <a href=\"#root/_help_CohkqWQC1iBv\">emojis</a>, type <code>:</code> followed by an emoji name to trigger an auto-completion.</li></ul><p>If auto-formatting is not desirable, press <kbd>Ctrl</kbd> + <kbd>Z</kbd> to revert the text to its original form.</p>",
"_help_YfYAtQBcfo5V": "<figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:350/193;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Math%20Equations_image.png\" width=\"350\" height=\"193\"></figure><p>Within text notes, it's possible to enter mathematical equations using the&nbsp;<span class=\"tn-icon cke cke-trilium-math\"></span> button from the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>&nbsp;(generally found under the&nbsp;<a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a>).</p><p>By default, the math dialog includes a MathLive visual editor and a TeX field. Disable <em>MathLive visual editor</em> under Options → Text Notes → Features to use only the TeX field and preview.</p><p>Enabling <em>Display mode</em> will render the equation slightly bigger (especially if using big operators such as summation, or fractions) and center it. Display mode equations will act as blocks (i.e. like paragraphs, or tables) and can be inserted for example in lists. Non-display equations can be part of the text.</p><h2>Keyboard shortcuts</h2><p>If inserting equations frequently, using the <kbd>Ctrl</kbd>+<kbd>M</kbd> keyboard shortcut can be more comfortable. Alternatively, type <code>$$</code> or <code>\\[</code> to trigger the popup directly.</p><p>There is currently no quick way to turn an already typed-out equation, such as surrounding it with <code>$</code> or pressing <kbd>Ctrl</kbd>+<kbd>M</kbd>.</p><h2>Supported math features</h2><p>Technically we are using the KaTeX library which allows for a subset of the TeX format. To see the full list of supported features, consult the <a href=\"https://katex.org/docs/supported\">Supported Functions</a> and the <a href=\"https://katex.org/docs/support_table\">Support Table</a> from the official documentation.</p><h2>Markdown support</h2><p>Math equations will be preserved when exporting to or importing from Markdown, surrounded by <code>$</code> characters for inline math expressions, and <code>$$</code> for display mode.</p><p>If you notice any issue with the Markdown import/export for equations, feel free to <a href=\"#root/_help_wy8So3yZZlH9\">report</a> it while providing the equation that causes issues.</p><h2>Formatting the equation</h2><p>It is possible to customize the font size and foreground color for both inline and display-mode equations, just like any other text. For inline equations, the background color/highlight can also be adjusted.</p>",
"_help_wYDzQ1fBFgfT": "<p>A multicolumn layout arranges content in two to four columns, side by side. A column can hold any kind of content, including tables, images and another multicolumn layout.</p><h2>Inserting a layout</h2><ul><li>In the formatting bar, go to <em>Insert</em> → <span class=\"tn-icon cke cke-trilium-multicolumn\"></span> <em>Columns</em> to insert a layout with two columns. Its submenu offers <em>2 columns</em>, <em>3 columns</em> and <em>4 columns</em>.</li><li>Alternatively, type <code>/columns</code> and choose <em>2 columns layout</em>, <em>3 columns layout</em> or <em>4 columns layout</em>, as described in&nbsp;<a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</li></ul><p>The columns of a new layout have equal widths. If text is selected when the layout is inserted, the selection moves into the first column.</p><h2>Changing the columns</h2><h3>Changing the layout</h3><p>While the cursor is inside a layout, a toolbar appears above it with a button that shows the current layout. Clicking it opens a row of figures, one for each available layout; hovering over a figure shows its number of columns and their widths:</p><figure class=\"table\"><table><thead><tr><th>Columns</th><th>Widths</th></tr></thead><tbody><tr><td>2</td><td>50%-50%, 25%-75%, 75%-25%</td></tr><tr><td>3</td><td>33%-33%-33%, 25%-50%-25%</td></tr><tr><td>4</td><td>25%-25%-25%-25%</td></tr></tbody></table></figure><ul><li>Choosing a layout with more columns adds empty columns at the end.</li><li>Choosing a layout with fewer columns removes the last columns and moves their content to the end of the last remaining column.</li></ul><h3>Adding columns</h3><p>While the cursor is in a column, you can use these key combinations:</p><ul><li><kbd>Ctrl</kbd> + <kbd>Enter</kbd>: Add a column after the current one.</li><li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Enter</kbd>: Add a column before the current one.</li></ul><p>The new column is empty and the cursor moves into it. All the columns then have equal widths. A layout has at most four columns, so the keys do nothing in a layout that already has four.</p><p><kbd>Ctrl</kbd> + <kbd>Enter</kbd> keeps its usual function on a link, in a to-do item and in the title of a collapsible block, and <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Enter</kbd> in a to-do item.</p><h3>Reordering columns</h3><p>While the cursor is anywhere inside a column, you can use these key combinations:</p><ul><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Right</kbd>: Move the column to the right.</li><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Left</kbd>: Move the column to the left.</li><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Home</kbd>: Make it the first column.</li><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>End</kbd>: Make it the last column.</li></ul><p>In a layout with two columns of different widths, the column keeps its width.</p><h2>Moving content between columns</h2><p>To move content to another column, select it, and then use these key combinations:</p><ul><li><kbd>Ctrl</kbd> + <kbd>Right</kbd>: Move to the column on the right.</li><li><kbd>Ctrl</kbd> + <kbd>Left</kbd>: Move to the column on the left.</li><li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>End</kbd>: Move to the last column.</li><li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Home</kbd>: Move to the first column.</li></ul><p>Paragraphs, list items, tables and other blocks move whole, even when only part of them is selected. Content moved to a column on the left goes to the end of that column, and content moved to a column on the right goes to its start, so it keeps its place in the reading order.</p><p>Without a selection, these keys keep their usual function: moving the cursor by word, or selecting up to the start or end of the column.</p><p>When a layout and <a class=\"reference-link\" href=\"#root/_help_EK2ckIZ74tbT\">Content tabs</a> are nested in one another, the key combinations act on the one closest to the cursor.</p><h2>Removing a layout</h2><ul><li>To remove the layout but keep its content, click the <span class=\"tn-icon cke cke-remove\"></span> <em>Remove layout</em> button in the layout's toolbar. The content of the columns is placed one after another where the layout was, and empty columns are left out.</li><li>To delete the layout together with its content, click the handle at its top-left corner to select it, then press <kbd>Delete</kbd>.</li></ul><h2>Narrow screens</h2><p>When a layout has too little room for its columns (narrower than about 500 pixels, such as on a phone), the columns are stacked one below the other. While editing, alternating background colors tell the columns apart. This applies to each layout on its own, so a layout inside a narrow column is stacked while the outer one stays side by side.</p><h2>Printing and exporting</h2><ul><li>When printing or <a href=\"#root/_help_NRnIZmSMc5sj\">exporting to PDF</a>, the columns are printed side by side.</li><li>Markdown has no columns, so Markdown export keeps the layout and each column as HTML <code>&lt;div&gt;</code> tags, with the content of each column written as Markdown between them. Importing the file back restores the layout. Markdown viewers that don't support HTML show the content of the columns one after another.</li></ul>",
"_help_dEHYtoWWi8ct": "<h2>Indentation</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:201/124;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Other%20features_image.png\" width=\"201\" height=\"124\"></figure><p>Paragraphs can be indented using the following buttons from the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:</p><ul><li>Press&nbsp;<span class=\"tn-icon cke cke-indent\"></span> to increase the indentation of the current paragraph by one. Can be pressed multiple times if needed.</li><li>Press&nbsp;<span class=\"tn-icon cke cke-outdent\"></span> to decrease the indentation of a current paragraph. The button will be disabled if it is already at the minimum indentation level.</li><li>For convenience, keyboard shortcuts are also available. Press <kbd>Tab</kbd> to indent or <kbd>Shift</kbd>+<kbd>Tab</kbd> to decrease the indentation. These shortcuts work even if the cursor is not at the beginning of a paragraph or a list.</li><li>Apart from paragraphs, the indent button is also enabled in&nbsp;<a class=\"reference-link\" href=\"#root/_help_S6Xx8QIWTV66\">Lists</a>&nbsp;(for nesting) and&nbsp;<a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a>.</li></ul><p>When indented paragraphs or headings are copied and pasted as plain text, for example into a <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note or another application, each indentation level becomes a tab at the start of the line. A copy that stays within a single paragraph contains only its text, without the indentation.</p><p>The reverse also works: when plain text is pasted into a text note, each paragraph whose lines all start with tabs is indented by one level per tab. Pasting into a code block keeps the tabs as they are.</p><h2>Markdown import</h2><p>If the clipboard contains Markdown text, it can be easily imported into text notes. Simply copy a Markdown-formatted text and press the&nbsp;<span class=\"tn-icon cke cke-trilium-markdown-mark\"></span> to insert its visual representation.</p><p>Note that this only works with raw Markdown (e.g. <code># Heading 1</code> to generate a heading) and not the visual representation of the Markdown (e.g. as in the preview pane of an application). In that case, simply use the paste function which already accepts HTML-formatted content.</p><p>This is mostly useful for snippets of text, for entire Markdown documents use the dedicated&nbsp;<a class=\"reference-link\" href=\"#root/_help_Oau6X9rCuegd\">Markdown</a>&nbsp;import/export function.</p><p>If accessing Trilium with a web browser, the Markdown import action will ask for the content to be inserted into a dedicated screen since it does not have access to the clipboard.</p><h2>Cut to subnote</h2><p>The&nbsp;<span class=\"tn-icon cke cke-trilium-scissors\"></span> button will create a child note with the selected text. For more information, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_2x0ZAX9ePtzV\">Cut to subnote</a>.</p><h2>Find and replace</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:394/203;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Other%20features_image.png\" width=\"394\" height=\"203\"></figure><p>The&nbsp;<span class=\"tn-icon cke cke-find-replace\"></span> button will open the editor's dedicated search and replace functionality.</p><p>Alternatively, the <kbd>Ctrl</kbd>+<kbd>F</kbd> combination can be pressed to show the dialog.</p>",
"_help_gLt3vA97tMcp": "<p>The text editor we are using is called&nbsp;<a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>&nbsp;which has an open-source core, but it's also a commercial product which offers <a href=\"https://ckeditor.com/docs/trial/latest/index.html\">premium features</a>.</p><p>Prior to v0.105.0, Trilium used the following premium features as part of a signed agreement between the CKEditor and the Trilium team:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a></li><li><a class=\"reference-link\" href=\"#root/_help_pwc194wlRzcH\">Text Snippets</a></li><li><a class=\"reference-link\" href=\"#root/_help_5wZallV2Qo1t\">Format Painter</a></li></ul><p>Starting with v0.105.0, those features have been completely rewritten as custom CKEditor plugins, licensed under AGPL-3.0.</p><h2>Lookalikes</h2><p>There are some premium CK features that look like Trilium's built-in functionality but they are completely different:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_VRoP0g1uHHc2\">In-editor AI assistant</a></li><li><a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a>&nbsp;which uses a third-party plugin that has been adapted for Trilium.</li></ul>",
"_help_ZlN4nump6EbW": "<figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:419/571;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Slash%20Commands_image.png\" width=\"419\" height=\"571\"></figure><p>Slash commands is a feature of&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;notes which allows easily accessing commonly used commands simply by using the keyboard, without having to remember dedicated&nbsp;<a class=\"reference-link\" href=\"#root/_help_A9Oc6YKKc65v\">Keyboard Shortcuts</a>.</p><h2>Interaction</h2><ul><li>As the name suggests, to trigger the slash commands simply press the / key to trigger it. Note that this can be anywhere in a paragraph as long as it's not part of the word, if it doesn't show up simply press a space and press the / key again.</li><li>Use ↑ and ↓ keys to navigate between options.</li><li>By default, the full list of commands is displayed.</li><li>To search, simply start typing: commands are found by their title or by other names they go by (for example <code>h2</code> for <em>Heading 2</em>).</li><li>To trigger the highlighted action, press Enter or Tab.</li></ul><h2>Integration with other features</h2><p>Apart from the common set of commands, some features are specially integrated with the slash commands:</p><ul><li>For <a href=\"#root/_help_NwBbFdNZ9h7O\">admonitions</a>, each admonition type (e.g. note, tip) will be individually displayed.</li><li>Every&nbsp;<a class=\"reference-link\" href=\"#root/_help_pwc194wlRzcH\">Text Snippets</a>&nbsp;will also appear individually, making it easy to insert them.</li><li><a class=\"reference-link\" href=\"#root/_help_VRoP0g1uHHc2\">In-editor AI assistant</a>: dedicated <em>Ask AI</em> item as well as all the predefined and <a href=\"#root/_help_mVEYwt20exhO\">custom quick actions</a>.</li></ul>",
+ "_help_0vgWgxQAWj4a": "<aside class=\"admonition important\"><p>Sorting the selection is experimental, and it changes as it matures. To use it, turn on <em>Sort selection in text editor</em> in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Advanced</em> → <em>Experimental Options</em>.</p></aside><p>Trilium can sort the items of a list, a group of paragraphs or the rows of a table in a text note, comparing numbers, dates and times by their value.</p><h2>Sorting</h2><ul><li>To sort, place the cursor in a list or a table, or select the paragraphs to sort, then press the <span class=\"tn-icon bx bx-sort-alt-2\"></span> <em>Sort</em> button of the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> to sort in ascending order. The arrow beside it offers <em>Ascending</em> and <em>Descending</em>. With the floating toolbar, the button is in the block-level popup.</li><li>When the selection covers several paragraphs, list items or table cells, the same choices are also in a submenu at the bottom of the menu of the block handle, the sequence of dots to the left of the block, and in the right-click menu of the selection. The submenu is named after what it sorts: <em>Sort blocks</em>, <em>Sort list items</em> or <em>Sort rows</em>.</li><li>On the&nbsp;<a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, the button is in the main row of the toolbar and in the row of the <em>List ›</em> button.</li></ul><p>A sort can be undone with <kbd>Ctrl</kbd>+<kbd>Z</kbd>.</p><h2>What is sorted</h2><ul><li><strong>List items</strong>: with the cursor in a list, the items at its level are sorted. Nested items move with the item they belong to and keep their own order. To sort only some of the items, select them.</li><li><strong>Paragraphs and other blocks</strong>: select two or more paragraphs, headings, quotes, collapsible blocks or images. Each block is sorted by its first text: a collapsible block by its title, a quote by its first paragraph and an image by its caption. A selection that mixes a list with other blocks cannot be sorted.</li><li><strong>Table rows</strong>: the rows are sorted by the column of the cursor, as described in <em>Sorting rows</em> in&nbsp;<a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a>. Inside a table cell, a list or several selected paragraphs are sorted instead of the rows.</li></ul><p>Values are compared the same way as table rows, see <em>How values are compared</em> in&nbsp;<a class=\"reference-link\" href=\"#root/_help_NdowYOC1GFKS\">Tables</a>.</p><h2>Limitations</h2><ul><li>The lines of a code block, or of a paragraph split with <kbd>Shift</kbd>+<kbd>Enter</kbd>, are not sorted one by one. A&nbsp;<a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note can sort its lines, see <em>Transforming text</em> there.</li></ul>",
"_help_oBo3iHIZnbG2": "<p>Trilium supports spell checking for your notes. How it works depends on whether you're using the <strong>desktop application</strong> (Electron) or accessing Trilium through a <strong>web browser</strong>.</p><h2>Desktop</h2><p>The desktop app uses Chromium's built-in spellchecker. You can configure it from <em>Options</em> → <em>Spell Check</em>.</p><h3>Enabling spell check</h3><p>Toggle <em>Check spelling</em> to enable or disable the spellchecker. A restart is required for changes to take effect — use the restart button at the bottom of the section.</p><h3>Choosing languages</h3><p>When spell check is enabled, a <em>Spell Check Languages</em> section appears listing all languages available on your system. Select one or more languages by checking the boxes. The spellchecker will accept words that are valid in <em>any</em> of the selected languages.</p><p>The available languages depend on your operating system's installed language packs. For example, on Windows you can add languages through <em>Options</em> → <em>Time &amp; Language</em> → <em>Language &amp; Region</em> → <em>Add a language</em>.</p><aside class=\"admonition note\"><p>The changes take effect only after restarting the application.</p></aside><h3>Custom dictionary</h3><aside class=\"admonition tip\"><p>This function is available starting with Trilium v0.103.0.</p></aside><p>Words you add to the dictionary (e.g. via the right-click context menu → \"Add to dictionary\") are stored in a <strong>synced note</strong> inside Trilium. This means your custom dictionary automatically syncs across all your devices.</p><p>You can view and edit the dictionary directly from <em>Settings</em> → <em>Spell Check</em> → <em>Custom Dictionary</em> → <em>Edit dictionary</em>. This opens the underlying note, which contains one word per line. You can add, remove, or modify entries as you like.</p><aside class=\"admonition note\"><p>Changes to the custom dictionary (whether from the editor or the context menu) take effect after restarting the application.</p></aside><h4>How the custom dictionary works</h4><ul><li>When you right-click a misspelled word and choose \"Add to dictionary\", the word is saved both to Electron's local spellchecker and to the synced dictionary note.</li><li>On startup, Trilium loads all words from the dictionary note into the spellchecker session.</li><li>If Trilium detects words in Electron's local dictionary but the dictionary note is empty (e.g. on first use), it performs a <strong>one-time import</strong> of those words into the note.</li><li>Words that are in Electron's local dictionary but <em>not</em> in the note (e.g. you removed them manually) are cleaned up from the local dictionary on startup.</li></ul><h4>Known limitations</h4><p>On Windows and macOS, Electron delegates \"Add to dictionary\" to the operating system's user dictionary. This means:</p><ul><li>Words added via the context menu are also written to the OS-level dictionary (e.g. <code>%APPDATA%\\Microsoft\\Spelling\\&lt;language&gt;\\default.dic</code> on Windows).</li><li><strong>Removing a word</strong> from the Trilium dictionary note prevents it from being loaded into the spellchecker on next startup, but does <em>not</em> remove it from the OS dictionary. The word may still be accepted by the OS spellchecker until you remove it from the OS dictionary manually.</li></ul><h2>Web browser</h2><p>When accessing Trilium through a web browser, spell checking is handled entirely by the browser itself. Trilium does not control the browser's spellchecker — language selection, dictionaries, and all other settings are managed through your browser's preferences.</p><p>The&nbsp;<a class=\"reference-link\" href=\"#root/_help_jcQVxzYybYgz\">Note contextual menu</a>&nbsp;has a special behavior in which a right-clicked word (without selection) shows the browser's default contextual menu which allows the spellcheck to function.</p><p>The Spell Check settings page in Trilium will indicate that these options apply only to desktop builds.</p><h2>Frequently asked questions</h2><h3>Do I need to restart after every change?</h3><p>Yes. Spell check language selection and the custom dictionary are loaded once at startup. Any changes require a restart to take effect.</p><h3>Can I use multiple spell check languages at the same time?</h3><p>Yes. Select as many languages as you need from the checklist. The spellchecker will accept words from any of the selected languages.</p><h3>My custom words disappeared after syncing to a new device — what happened?</h3><p>On the first launch of a new device, Trilium may import existing local dictionary words into the note. If the note already has words from another device (via sync), those are preserved. Make sure sync completes before restarting the application on a new device.</p><h3>I removed a word from the dictionary note but it's still accepted</h3><p>This is likely due to the OS-level dictionary retaining the word (see <a href=\"#known-limitations\">Known limitations</a> above). You can manually remove it from your operating system's user dictionary.</p>",
"_help_BFvAtE74rbP6": "<aside class=\"admonition note\"><p>This page has been relocated to&nbsp;<a class=\"reference-link\" href=\"#root/_help_2dcGDhp9WFKb\">Outline tab</a>.</p></aside>",
"_help_NdowYOC1GFKS": "<p>Tables are a powerful feature for&nbsp;<a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a>&nbsp;notes, since editing them is generally easy.</p><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:176/204;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Tables_image.png\" width=\"176\" height=\"204\"></figure><p>To create a table, simply press the table button and select with the mouse the desired amount of columns and rows, as indicated in the adjacent figure.</p><p>Since v0.107.0, the same menu starts with an <em>Insert table…</em> item, for a table larger than the grid or to type its size instead:</p><ol><li>Click the <span class=\"tn-icon cke cke-table\"></span>button and select <em>Insert table…</em>. A small form opens at the cursor.</li><li>Enter the number of <em>Columns</em> (up to 100) and <em>Rows</em> (up to 1000). The table can have at most 5000 cells in total, for example 1000 rows of 5 columns.</li><li>Optionally, turn on <em>Use headers</em> and enter the number of <em>Header columns</em> and <em>Header rows</em>. A table cannot have more header columns or rows than it has columns or rows.</li><li>Press <em>Insert</em> or <kbd>Enter</kbd>.</li></ol><p>To close the form without inserting a table, press <kbd>Esc</kbd> or click outside it. From the keyboard, <kbd>Tab</kbd> moves between <em>Insert table…</em> and the grid while the menu is open.</p><p>On the <a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, the table is inserted from the <span class=\"tn-icon cke cke-plus\"></span> button of the formatting toolbar: its <em>Insert table</em> tile lists common sizes, from 2 × 2 to 3 × 4 (rows × columns). Tap one to insert a table of that size; to make it larger, insert rows and columns afterwards.</p><h2>Formatting toolbar</h2><p>When a table is selected, a special formatting toolbar will appear:</p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_Tables_image.png\" width=\"384\" height=\"100\"><p>On the <a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, the toolbar does not float over the table. Instead, press the <span class=\"tn-icon cke cke-table\"></span> button after <em>Undo</em> and <em>Redo</em> in the formatting toolbar at the bottom of the screen to show the table's toolbar there.</p><h2>Context menu</h2><p>Since v0.106.0, right-clicking anywhere inside a table opens a context menu with the most common table operations:</p><ul><li><em>Insert row above</em> and <em>Insert row below</em> insert a blank row next to the row of the current cell. When the selection spans multiple rows, the same number of rows is inserted.</li><li><em>Insert column to the left</em> and <em>Insert column to the right</em> work the same way for columns.</li><li>Since v0.107.0, <em>Set as header</em> or <em>Set header up to this row</em>, depending on the selection, turns rows into header rows, which always start at the top of the table:<ul><li><em>Set as header</em> shows when the selection starts at the first row, and makes every selected row a header row.</li><li><em>Set header up to this row</em> shows when the selection is in a single row below the first, and makes that row and every row above it header rows.</li><li>Neither shows when the selection spans several rows below the first.</li><li>A check mark shows that the rows are already header rows. Choosing the item again turns them, and every header row below them, back into regular rows. For example, in a table with five header rows, choosing <em>Set header up to this row</em> on the third row leaves only the first two as header rows.</li></ul></li><li><em>Merge cells</em> merges the selected cells into one. The selected cells must form a rectangle.</li><li><em>Split cell</em> splits each selected cell in two, either <em>Vertically</em> or <em>Horizontally</em>. <em>Unmerge cells</em>, in the same submenu, turns each merged cell in the selection back into the single cells it covers, keeping its content in the top-left one; cells that are not merged stay as they are.</li><li><em>Distribute columns evenly</em> splits the combined width of the columns the selection touches equally between them. The other columns and the width of the table stay as they are. It needs a selection spanning at least two columns; a merged cell counts for every column it covers.</li><li><em>Cut</em>, <em>Copy</em> and <em>Copy as Markdown</em> act on the selected cells. Since v0.107.0, <em>Copy</em> and <em>Paste</em> open submenus with their variants, such as <em>Copy as Markdown</em> and <em>Paste as plain text</em>; clicking <em>Copy</em> or <em>Paste</em> itself still copies or pastes:<ul><li>Cutting or copying produces a smaller table holding just the selected cells. Pasting it over a cell selection replaces those cells; pasting elsewhere inserts it as a table of its own. Cutting clears the cells without removing rows or columns.</li><li><em>Copy as Markdown</em> converts the selected cells to a Markdown table. A selected header row becomes the Markdown header; without one, an empty header row is emitted, since Markdown tables require one.</li></ul></li><li>Since v0.107.0, <em>Paste rows above</em> and <em>Paste rows below</em>, in the <em>Paste</em> submenu, paste the clipboard as new rows next to the row of the current cell, instead of over the cells from the cursor on. They show only when the selection is in a single row, and, like <em>Paste</em>, only where the clipboard can be read:<ul><li>A copied table becomes one new row for each of its rows, filled from the first column. When it has more columns than the table, the table gains columns, as with a regular paste. Other content goes in the first cell of a single new row.</li><li>The new rows are selected afterwards.</li><li>When merged cells join the row to others, the new rows go above or below that whole block of rows.</li></ul></li><li><em>Sort</em>, below the clipboard section, sorts the rows by the column of the current cell, in <em>Ascending</em> or <em>Descending</em> order. See <a href=\"#sorting-rows\">Sorting rows</a>.</li><li><em>Delete row</em> and <em>Delete column</em>, below <em>Sort</em>, remove every row or column the selection touches, even when only some of their cells are selected.</li><li><em>Delete table</em> removes the whole table and leaves an empty paragraph in its place. In a table nested inside another, only the inner table is removed.</li><li>Since v0.107.0, <em>Select</em>, below <em>Delete table</em>, selects the cells of every row (<em>Row</em>) or column (<em>Column</em>) the selection touches, or every cell of the table (<em>Table</em>). Unlike the <span class=\"tn-icon cke cke-drag-handle\"></span>button, which selects the table as a whole, <em>Table</em> selects its cells, so cell operations such as <em>Merge cells</em> apply to all of them. In a table nested inside another, <em>Table</em> selects only the cells of the inner table.</li></ul><p>Right-clicking a cell that is not part of the current selection moves the cursor there first, so the menu always applies to the cell under the pointer.</p><aside class=\"admonition note\"><p>In the browser, Trilium's menu replaces the browser's own context menu inside tables. To reach the browser's menu (for example for its spell checking suggestions), hold <kbd>Shift</kbd> while right-clicking. The desktop application is unaffected, since its menu already includes the spelling suggestions. In the browser, the menu also offers <em>Paste</em> only when the page can read the clipboard, which requires a secure (HTTPS) context and your permission; otherwise, paste with <kbd>Ctrl</kbd>+<kbd>V</kbd>.</p></aside><h2>Navigating a table</h2><ul><li>Using the mouse:<ul><li>Click on a cell to focus it.</li><li>Click the&nbsp;<span class=\"tn-icon cke cke-return-arrow\"></span> button at the top or the bottom of a table to insert an empty paragraph near it.</li><li>Click the&nbsp;<span style=\"--tn-color:hsl(0,0%,60%);color:hsl(0,0%,60%);\"><span class=\"tn-icon cke cke-drag-handle\"></span></span> button at the top-left of the table to select it entirely (for easy copy-pasting or cutting) or drag and drop it to relocate the table.</li></ul></li><li>Using the keyboard:<ul><li>Use the arrow keys on the keyboard to easily navigate between cells.</li><li>It's also possible to use <kbd>Tab</kbd> to go to the next cell and Shift+Tab to go to the previous cell.</li><li>Unlike arrow keys, pressing <kbd>Tab</kbd> at the end of the table (last row, last column) will create a new row automatically.</li><li>To select multiple cells, hold <kbd>Shift</kbd> while using the arrow keys.</li></ul></li><li>Using touch:<ul><li>Since v0.107.0, touching a table outlines the cell with the cursor, or the selected cells, and shows a handle at each corner of the outline.</li><li>To select multiple cells, drag one of the handles across the table. The cell at the opposite corner stays selected, so the selection grows or shrinks as the finger moves. The note and wide tables scroll when the handle reaches the edge of the screen.</li></ul></li></ul><h2>Resizing cells</h2><ul><li>Columns can be resized by hovering the mouse over the border of two adjacent cells and dragging it.</li><li>To give several columns the same width, select cells across them and choose <em>Distribute columns evenly</em> from the <span class=\"tn-icon cke cke-table-column\"></span>button of the formatting toolbar or from the <a href=\"#context-menu\">context menu</a>.</li><li>By default, the row height is not adjustable using the mouse, but it can be configured from the cell settings (see below).</li><li>To adjust exactly the width (in pixels or percentages) of a cell, select the&nbsp;<span class=\"tn-icon cke cke-table-cell-properties\"></span> button.</li></ul><h3>Resizing with touch</h3><p>Since v0.107.0, touching a table shows a bar at the bottom of the note, above the formatting toolbar on mobile. The bar has a segment for each column of the table, with a divider at the end of each column. Only the divider of the column with the cursor is a handle that resizes; the other dividers only mark where the columns meet, so a swipe across them scrolls instead. When several cells are selected, each column they cover has a handle.</p><ul><li>To resize a column, place the cursor in one of its cells or tap its segment, then drag its handle. The table grows or shrinks with the column, and scrolls when the handle reaches the edge of the screen. The column snaps to its starting width and to the widths of the columns beside it.</li><li>To cancel a resize, drag the handle back to where it started, or touch the screen with a second finger.</li><li>To give a column and the next one the same width, double-tap the handle between them.</li><li>To select a column, tap its segment. To open the column menu, touch and hold the segment.</li><li>To scroll a wide table sideways, swipe along the bar.</li></ul><p>A wide table scrolls a little past its end, so the handle of its last column stays away from the edge of the screen, where a swipe navigates back.</p><h2>Wide tables</h2><p>Since v0.107.0, a table can be wider than the&nbsp;<a class=\"reference-link\" href=\"#root/_help_t596jLvPrqkS\">Content width</a>. Such a table scrolls sideways, while the rest of the note keeps its width.</p><ul><li>A new table is as wide as the content. To make it wider, drag the right border of its last column past the edge of the content. The border snaps to the edge and holds there briefly, so the table is easy to bring back to the width of the content.</li><li>To set an exact width, enter a percentage above <code>100%</code> or a width in pixels in the&nbsp;<span class=\"tn-icon cke cke-table-properties\"></span> <a href=\"#table-properties\">table properties</a>.</li><li>A table whose content needs more room than the note, such as a pasted table with many columns, also scrolls instead of stretching the note.</li><li>Wide tables scroll the same way in read-only notes and on shared pages.</li><li>When printing or exporting to PDF, a wide table is shrunk to fit the page.</li></ul><p>Tables inside other blocks, such as block quotes, admonitions, collapsible blocks, columns or tabs, are limited to the width of their block and do not scroll.</p><h3>Mobile support</h3><p>On the&nbsp;<a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, a table keeps the width it has on a desktop and scrolls sideways, instead of squeezing its columns into the width of the screen. The full width of a table is the <em>Max content width</em> set in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Appearance</em> → <em>Content Width</em> on the mobile device, 1200 pixels by default. For example, a table set to <code>50%</code> is 600 pixels wide.</p><p>To resize columns on mobile, use the bar described in <a href=\"#resizing-with-touch\">Resizing with touch</a>.</p><h2>Long tables</h2><p>Since v0.107.0, the header rows of a table stay visible at the top of the note while you scroll through the rest of the table, and leave with the end of the table. This also works in read-only notes, on shared pages and in wide tables.</p><p>To turn rows into header rows, use <em>Set as header</em> in the <a href=\"#context-menu\">context menu</a>, or <em>Header row</em> in the <span class=\"tn-icon cke cke-table-row\"></span> button of the formatting toolbar.</p><p>To let header rows scroll away with the rest of the table, turn off <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text Notes</em> → <em>Features</em> → <em>Use sticky header rows for tables</em>. The setting applies to the current device only, and shared pages keep their sticky header rows.</p><h2>Inserting new rows and new columns</h2><ul><li>To insert a new column, click on a desired location, then press the&nbsp;<span class=\"tn-icon cke cke-table-column\"></span> button from the formatting toolbar and select <em>Insert column left or right.</em></li><li>To insert a new row, click on a desired location, then press the&nbsp;<span class=\"tn-icon cke cke-table-row\"></span> button and select <em>Insert row above</em> or <em>below</em>.<ul><li>A quicker alternative to creating a new row while at the end of the table is to press the <kbd>Tab</kbd> key.</li></ul></li><li>Both operations are also available in the <a href=\"#context-menu\">context menu</a>, which inserts as many rows or columns as the selection spans.</li></ul><h2>Moving rows and columns</h2><p>Since v0.106.0, rows and columns can be reordered with the keyboard:</p><ul><li><kbd>Alt</kbd>+<kbd>Up</kbd> and <kbd>Alt</kbd>+<kbd>Down</kbd> move the rows touched by the selection up or down.</li><li><kbd>Alt</kbd>+<kbd>Left</kbd> and <kbd>Alt</kbd>+<kbd>Right</kbd> move the columns touched by the selection left or right.</li></ul><p>Merged cells are never split by a move. The rows or columns held together by a merged cell travel as one block, and moving toward such a block jumps over it entirely.</p><p>When the table has a header row, a header row moved below the header area becomes a regular row, and a regular row moved into the header area becomes a header row. Header columns behave the same way.</p><p>Outside of tables, <kbd>Alt</kbd>+<kbd>Left</kbd> and <kbd>Alt</kbd>+<kbd>Right</kbd> keep navigating the note history, and <kbd>Alt</kbd>+<kbd>Up</kbd> and <kbd>Alt</kbd>+<kbd>Down</kbd> keep moving the current paragraph.</p><h2>Sorting rows</h2><p>Since v0.107.0, the rows of a table can be sorted by the values of one column:</p><ul><li>To sort all the rows, place the cursor in any cell of the column to sort by, then select <em>Sort</em> → <em>Ascending</em> or <em>Descending</em> from the <a href=\"#context-menu\">context menu</a>. The same items are in the <span class=\"tn-icon bx bx-sort-alt-2\"></span>button of the formatting toolbar.</li><li>To sort only some of the rows, select their cells in the column to sort by, then sort the same way. Sorting is not available while the selection spans more than one column.</li></ul><p>Header rows always stay at the top of the table and are never sorted. A sort can be undone with <kbd>Ctrl</kbd>+<kbd>Z</kbd>.</p><h3>How values are compared</h3><p>Each cell is read as plain text, so formatting does not affect the order. Trilium then detects what kind of value the cell holds:</p><figure class=\"table\"><table><thead><tr><th>Kind</th><th>Examples</th><th>Compared by</th></tr></thead><tbody><tr><td>Time</td><td><code>15:02</code>, <code>15:02:38</code>, <code>3:02 PM</code></td><td>The time of day.</td></tr><tr><td>Date</td><td><code>2026-09-30</code>, <code>2026-09-30 15:02</code>, <code>30 September 2026</code>, <code>Wednesday, 30 September 2026</code>, <code>2026-09-30T15:02:38+03:00</code></td><td>The date and time.</td></tr><tr><td>Number</td><td><code>12</code>, <code>-3.5</code>, <code>1,234.56</code>, <code>$ 12.04</code>, <code>21 RON</code>, <code>24.5m</code></td><td>The numeric value.</td></tr><tr><td>Text</td><td>Anything else.</td><td>Alphabetically, ignoring case, with numbers inside the text in numeric order (<code>Item 9</code> before <code>Item 10</code>). Accents count, so <code>a</code> and <code>á</code> differ.</td></tr><tr><td>Empty</td><td>An empty cell, or one holding only spaces.</td><td>Not compared. Empty cells always go last.</td></tr></tbody></table></figure><p>Ascending order puts times first, then dates, numbers and text. Descending order reverses it. Empty cells go last in both directions.</p><p>Numbers, dates and times with the same value are ordered by their text, so <code>5 apples</code> comes before <code>5 pears</code>. Rows whose cells hold the same text, ignoring case, keep their relative order.</p><ul><li>Dates are also recognized in the formats of the note's language, such as <code>30.09.2026</code> or <code>30. September 2026</code> for German, and in the format chosen in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Text Notes</em> → <em>Editor</em> → <em>Date/time format</em> for <a href=\"#root/_help_CohkqWQC1iBv\">inserting the date and time</a>.</li><li>A number can start with a currency symbol, such as <code>$</code>, <code>€</code> or <code>£</code>. Whatever follows the number, such as a unit, is ignored, so units are not converted: <code>1 km</code> sorts before <code>500 m</code>. A cell that starts with letters, such as <code>RON 21</code>, is text.</li><li>The decimal separator follows the language of the note: <code>1.500</code> is one and a half in English, but one thousand five hundred in German. A comma or period that is not followed by exactly three digits is always read as a decimal separator, so <code>1,5</code> is one and a half in either language.</li><li>The language of the note set in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a>&nbsp;via the&nbsp;<span class=\"tn-icon bx bx-globe\"></span> icon, or else the default content language. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_veGu4faJErEM\">Content language &amp; Right-to-left support</a>.</li></ul><h3>Merged cells</h3><p>Rows joined by a merged cell are kept together and move as one block. The block is sorted by the value in its first row. When the block has more than one cell in the sorted column, the other cells do not affect the order, and a message says so: <em>Some rows were sorted together because merged cells tie them to each other</em>.</p><p>When the selection covers only part of such a block, the whole block is sorted.</p><h2>Merging cells</h2><p>To merge two or more cells together, simply select them via drag &amp; drop and press the&nbsp;<span class=\"tn-icon cke cke-table-merge-cell\"></span> button from the formatting toolbar.</p><p>More options are available by pressing the arrow next to it:</p><ul><li>Click on a single cell and select Merge cell up/down/right/left to merge with an adjacent cell.</li><li>Select <em>Merge selected cells</em> to merge the selected cells, the same as pressing the button itself.</li><li>Select <em>Split cell vertically</em> or <em>horizontally</em>, to split a cell into multiple cells (can also be used to undo a merge).</li><li>Select <em>Unmerge cells</em> to turn each merged cell in the selection back into the single cells it covers, keeping its content in the top-left one.</li></ul><p><em>Merge selected cells</em> and <em>Unmerge cells</em> are available since v0.107.0. Merging and splitting are also available by right-clicking the selected cells, via the <a href=\"#context-menu\">context menu</a>, where <em>Unmerge cells</em> is in the <em>Split cell</em> submenu.</p><h2>Table properties</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:312/311;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Tables_image.png\" width=\"312\" height=\"311\"></figure><p>The table properties can be accessed via the&nbsp;<span class=\"tn-icon cke cke-table-properties\"></span> button and allows for the following adjustments:</p><ul><li>Border (not the border of the cells, but the outer rim of the table), which includes the style (single, double), color and width.</li><li>The background color, with none set by default.</li><li>The width and height of the table in percentage (must end with <code>%</code>) or pixels (must end with <code>px</code>).</li><li>The alignment of the table.<ul><li>Left or right-aligned, case in which the text will flow next to it.</li><li>Centered, case in which text will avoid the table, regardless of the table width.</li></ul></li></ul><p>The table will immediately update to reflect the changes, but the <em>Save</em> button must be pressed for the changes to persist.</p><h2>Cell properties</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:320/386;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Tables_image.png\" width=\"320\" height=\"386\"></figure><p>Similarly to table properties, the&nbsp;<span class=\"tn-icon cke cke-table-cell-properties\"></span> button opens a popup which adjusts the styling of one or more cells (based on the user's selection).</p><p>The following options can be adjusted:</p><ul><li>The border style, color and width (same as table properties), but applying to the current cell only.</li><li>The background color, with none set by default.</li><li>The width and height of the cell in percentage (must end with <code>%</code>) or pixels (must end with <code>px</code>).</li><li>The padding (the distance of the text compared to the cell's borders).</li><li>The alignment of the text, both horizontally (left, centered, right, justified) and vertically (top, middle or bottom).<ul><li>In a centered or right-aligned cell, each item of a bulleted, numbered or to-do list moves together with its bullet, number or checkbox.</li></ul></li></ul><p>The cell will immediately update to reflect the changes, but the <em>Save</em> button must be pressed for the changes to persist.</p><h2>Border and background colors</h2><p>The border and background colors of tables and cells adapt to the <a href=\"#root/_help_Wy267RK4M69c\">theme</a>, the same way as <a href=\"#root/_help_Gr6xFaF6ioJ5\">text colors</a> do. A color picked from the palette, chosen with the color picker or typed in is shown in a lighter or darker shade that suits the current theme, so borders stay visible and text stays readable on the background. The hue stays the same, and the table keeps the color as it was picked.</p><p>Colors applied with older versions of Trilium are shown exactly as they were picked, until the note is next edited.</p><p>Older browsers that can't adapt colors show them exactly as they were picked.</p><h2>Caption</h2><p>Press the&nbsp;<span class=\"tn-icon cke cke-caption\"></span> button to insert a caption or a text description of the table, which is going to be displayed above the table.</p><h2>Table borders</h2><p>By default, tables come with a gray border that is lighter or darker to suit the current <a href=\"#root/_help_Wy267RK4M69c\">theme</a>, so it stays discreet on a dark background.</p><p>To change the default border of every table, set the <code>--text-note-table-border-color</code> variable in a <a href=\"#root/_help_7NfNr5pZpVKV\">custom theme</a> or in <a href=\"#root/_help_AlhDUqhENtH7\">custom app-wide CSS</a>, for example <code>:root { --text-note-table-border-color: #555; }</code>. Set it to <code>transparent</code> to hide the borders of all the tables that don't have a border of their own.</p><p>To adjust the borders, follow these steps:</p><ol><li>Select the table.</li><li>In the floating panel, select the <em>Table properties</em> option (<span class=\"tn-icon cke cke-table-properties\"></span>).<ol><li>Look for the <em>Border</em> section at the top of the newly opened panel.</li><li>This will control the outer borders of the table.</li><li>Select a style for the border. Generally <em>Single</em> is the desirable option.</li><li>Select a color for the border.</li><li>Select a width for the border, expressed in pixels.</li></ol></li><li>Select all the cells of the table and then press the <em>Cell properties</em> option (<span class=\"tn-icon cke cke-table-cell-properties\"></span>).<ol><li>This will control the inner borders of the table, at cell level.</li><li>Note that it's possible to change the borders individually by selecting one or more cells, case in which it will only change the borders that intersect these cells.</li><li>Repeat the same steps as from step (2).</li></ol></li></ol><h3>Tables with invisible borders</h3><p>Tables can be set to have invisible borders in order to allow for basic layouts (columns, grids) of text or <a href=\"#root/_help_mT0HEkOsz6i1\">images</a> without the distraction of their border:</p><ol><li>First insert a table with the desired number of columns and rows.</li><li>Select the entire table.</li><li>In <em>Table properties</em>, set:<ol><li><em>Style</em> to <em>Single</em></li><li><em>Color</em> to <code>transparent</code></li><li>Width to <code>1px</code>.</li></ol></li><li>In Cell Properties, set the same as on the previous step.</li></ol><h2>Table indentation</h2><p>Since v0.104.1, tables can be indented as a block (the whole table moves, rather than just the content of a cell).</p><ol><li>Click the&nbsp;<span style=\"--tn-color:hsl(0,0%,60%);color:hsl(0,0%,60%);\"><span class=\"tn-icon cke cke-drag-handle\"></span></span> button to select the entire table. Otherwise, the indentation applies only to the current cell's content.</li><li>Press <kbd>Tab</kbd> to increase the indent, or <kbd>Shift</kbd>+<kbd>Tab</kbd> to decrease it. Alternatively, use the indentation buttons in the formatting toolbar.</li></ol><p>Markdown does not support indented tables, so the indentation is lost when converting to Markdown.</p><h2>Markdown import/export</h2><p>Simple tables are exported in GitHub-flavored Markdown format (e.g. a series of <code>|</code> items). If the table is found to be more complex (it contains HTML elements, has custom sizes or images), the table is converted to a HTML one instead.</p><p>Generally formatting loss should be minimal when exported to Markdown due to the fallback to HTML formatting.</p>",
diff --git a/apps/server/src/assets/help/help_meta.json b/apps/server/src/assets/help/help_meta.json
index 9ca83c666d..ec4c754bb5 100644
--- a/apps/server/src/assets/help/help_meta.json
+++ b/apps/server/src/assets/help/help_meta.json
@@ -183,6 +183,7 @@
{"id":"_help_dEHYtoWWi8ct","title":"Other features","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/other-features"},{"type":"label","name":"iconClass","value":"bx bxs-grid"}]},
{"id":"_help_gLt3vA97tMcp","title":"Premium features","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/premium-features"},{"type":"label","name":"iconClass","value":"bx bx-star"}]},
{"id":"_help_ZlN4nump6EbW","title":"Slash Commands","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/slash-commands"},{"type":"label","name":"iconClass","value":"bx bx-menu"}]},
+ {"id":"_help_0vgWgxQAWj4a","title":"Sorting","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/sorting"},{"type":"label","name":"iconClass","value":"bx bx-sort-alt-2"}]},
{"id":"_help_oBo3iHIZnbG2","title":"Spell Check","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/spellcheck"},{"type":"label","name":"iconClass","value":"bx bx-check-double"}]},
{"id":"_help_BFvAtE74rbP6","title":"Table of contents","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/table-of-contents"},{"type":"label","name":"iconClass","value":"bx bx-heading"}]},
{"id":"_help_NdowYOC1GFKS","title":"Tables","type":"text","attributes":[{"type":"label","name":"docUrl","value":"https://docs.triliumnotes.org/user-guide/note-types/text/tables"},{"type":"label","name":"iconClass","value":"bx bx-table"}]},
diff --git a/docs/User Guide/!!!meta.json b/docs/User Guide/!!!meta.json
index 89af66afb3..ee8a3df374 100644
--- a/docs/User Guide/!!!meta.json
+++ b/docs/User Guide/!!!meta.json
@@ -6533,6 +6533,41 @@
}
]
},
+ {
+ "isClone": false,
+ "noteId": "0vgWgxQAWj4a",
+ "notePath": [
+ "pOsGYCXsbNQG",
+ "KSZ04uQ2D1St",
+ "iPIMuisry3hd",
+ "0vgWgxQAWj4a"
+ ],
+ "title": "Sorting",
+ "notePosition": 290,
+ "prefix": null,
+ "isExpanded": false,
+ "type": "text",
+ "mime": "text/html",
+ "attributes": [
+ {
+ "type": "label",
+ "name": "shareAlias",
+ "value": "sorting",
+ "isInheritable": false,
+ "position": 10
+ },
+ {
+ "type": "label",
+ "name": "iconClass",
+ "value": "bx bx-sort-alt-2",
+ "isInheritable": false,
+ "position": 20
+ }
+ ],
+ "format": "markdown",
+ "dataFileName": "Sorting.md",
+ "attachments": []
+ },
{
"isClone": false,
"noteId": "oBo3iHIZnbG2",
@@ -6543,7 +6578,7 @@
"oBo3iHIZnbG2"
],
"title": "Spell Check",
- "notePosition": 290,
+ "notePosition": 300,
"prefix": null,
"isExpanded": false,
"type": "text",
@@ -6578,7 +6613,7 @@
"BFvAtE74rbP6"
],
"title": "Table of contents",
- "notePosition": 300,
+ "notePosition": 310,
"prefix": null,
"isExpanded": false,
"type": "text",
@@ -6613,7 +6648,7 @@
"NdowYOC1GFKS"
],
"title": "Tables",
- "notePosition": 310,
+ "notePosition": 320,
"prefix": null,
"isExpanded": false,
"type": "text",
@@ -6681,7 +6716,7 @@
"pwc194wlRzcH"
],
"title": "Text Snippets",
- "notePosition": 320,
+ "notePosition": 330,
"prefix": null,
"isExpanded": false,
"type": "text",
@@ -6710,7 +6745,7 @@
"fASfBrYnquKU"
],
"title": "To-do Lists",
- "notePosition": 330,
+ "notePosition": 340,
"prefix": null,
"isExpanded": false,
"type": "text",
diff --git a/docs/User Guide/User Guide/Note Types/Text.md b/docs/User Guide/User Guide/Note Types/Text.md
index 995644b3b5..2348161816 100644
--- a/docs/User Guide/User Guide/Note Types/Text.md
+++ b/docs/User Guide/User Guide/Note Types/Text.md
@@ -70,7 +70,7 @@ Here's a list of various features supported by text notes:
</tr>
<tr>
<td><a class="reference-link" href="Text/Other%20features.md">Other features</a></td>
- <td><ul><li>Indentation<ul><li>Markdown import</li></ul></li><li><a class="reference-link" href="Text/Cut%20to%20subnote.md">Cut to subnote</a></li></ul></td>
+ <td><ul><li>Indentation<ul><li>Markdown import</li></ul></li><li><a class="reference-link" href="Text/Cut%20to%20subnote.md">Cut to subnote</a></li><li><a class="reference-link" href="Text/Sorting.md">Sorting</a></li></ul></td>
</tr>
<tr>
<td><a class="reference-link" href="Text/Premium%20features.md">Premium features</a></td>
diff --git a/docs/User Guide/User Guide/Note Types/Text/Lists.md b/docs/User Guide/User Guide/Note Types/Text/Lists.md
index 7ea98fb682..a966b074d6 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Lists.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Lists.md
@@ -60,6 +60,10 @@ It possible to add content-level blocks such as headings, code blocks, tables wi
The same principle applies to all three list types (bullet, numbered and to-do).
+## Sorting
+
+The items of a list can be sorted, nested items moving with the item they belong to. This is experimental, see <a class="reference-link" href="Sorting.md">Sorting</a>.
+
## Alignment
A list item can be centered or aligned to the right, either with the text alignment button in the formatting toolbar or by aligning the <a class="reference-link" href="Tables.md">Tables</a> cell that contains the list. The bullet, number or checkbox then moves together with the text of the item.
diff --git a/docs/User Guide/User Guide/Note Types/Text/Sorting.md b/docs/User Guide/User Guide/Note Types/Text/Sorting.md
new file mode 100644
index 0000000000..9213c75a46
--- /dev/null
+++ b/docs/User Guide/User Guide/Note Types/Text/Sorting.md
@@ -0,0 +1,25 @@
+# Sorting
+> [!IMPORTANT]
+> Sorting the selection is experimental, and it changes as it matures. To use it, turn on _Sort selection in text editor_ in <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/UI%20Elements/Options.md">Options</a> → _Advanced_ → _Experimental Options_.
+
+Trilium can sort the items of a list, a group of paragraphs or the rows of a table in a text note, comparing numbers, dates and times by their value.
+
+## Sorting
+
+* To sort, place the cursor in a list or a table, or select the paragraphs to sort, then press the <span class="tn-icon bx bx-sort-alt-2"></span> _Sort_ button of the <a class="reference-link" href="Formatting%20toolbar.md">Formatting toolbar</a> to sort in ascending order. The arrow beside it offers _Ascending_ and _Descending_. With the floating toolbar, the button is in the block-level popup.
+* When the selection covers several paragraphs, list items or table cells, the same choices are also in a submenu at the bottom of the menu of the block handle, the sequence of dots to the left of the block, and in the right-click menu of the selection. The submenu is named after what it sorts: _Sort blocks_, _Sort list items_ or _Sort rows_.
+* On the <a class="reference-link" href="../../Installation%20%26%20Setup/Mobile%20Frontend.md">Mobile Frontend</a>, the button is in the main row of the toolbar and in the row of the _List ›_ button.
+
+A sort can be undone with <kbd>Ctrl</kbd>+<kbd>Z</kbd>.
+
+## What is sorted
+
+* **List items**: with the cursor in a list, the items at its level are sorted. Nested items move with the item they belong to and keep their own order. To sort only some of the items, select them.
+* **Paragraphs and other blocks**: select two or more paragraphs, headings, quotes, collapsible blocks or images. Each block is sorted by its first text: a collapsible block by its title, a quote by its first paragraph and an image by its caption. A selection that mixes a list with other blocks cannot be sorted.
+* **Table rows**: the rows are sorted by the column of the cursor, as described in _Sorting rows_ in <a class="reference-link" href="Tables.md">Tables</a>. Inside a table cell, a list or several selected paragraphs are sorted instead of the rows.
+
+Values are compared the same way as table rows, see _How values are compared_ in <a class="reference-link" href="Tables.md">Tables</a>.
+
+## Limitations
+
+* The lines of a code block, or of a paragraph split with <kbd>Shift</kbd>+<kbd>Enter</kbd>, are not sorted one by one. A <a class="reference-link" href="../Code.md">Code</a> note can sort its lines, see _Transforming text_ there.
\ No newline at end of file
diff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.ts
index 8ca1d40f4e..484c280c4b 100644
--- a/packages/ckeditor5/src/index.ts
+++ b/packages/ckeditor5/src/index.ts
@@ -41,6 +41,7 @@ export type { LinkEmbedHost } from "./plugins/link_embed/link_embed_commands.js"
export type { AttachmentUploadHost } from "./plugins/uploadimage.js";
export type { IconPickerRequest } from "./plugins/inline_icon/inline_icon_ui.js";
export type { BlockReferenceHost } from "./plugins/block_reference/block_reference.js";
+export type { SortTargetKind } from "./plugins/sort_selection/sort_targets.js";
export type { ColorMenuHost, ColorMenuRequest, ColorMenuTarget } from "./plugins/color_menu.js";
export { default as TriliumSnippets } from "./plugins/snippets/snippets.js";
export type { SnippetDefinition } from "./plugins/snippets/snippetsconfig.js";
@@ -65,6 +66,7 @@ import "./plugins/tabs/tabs.js";
import "./plugins/multicolumn/multicolumn.js";
import "./plugins/mermaid/mermaid.js";
import "./plugins/referencelink.js";
+import "./plugins/sort_selection/sort_selection.js";
import "./plugins/table_column_bar/table_column_bar.js";
import "./plugins/table_context_menu.js";
import "./plugins/table_paste_rows.js";
diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts
index a1093e9ffa..ded96e39fd 100644
--- a/packages/ckeditor5/src/plugins.ts
+++ b/packages/ckeditor5/src/plugins.ts
@@ -75,6 +75,7 @@ import TableContextMenu from "./plugins/table_context_menu.js";
import TableMove from "./plugins/table_move/table_move.js";
import TablePasteRows from "./plugins/table_paste_rows.js";
import TableSort from "./plugins/table_sort.js";
+import SortSelection from "./plugins/sort_selection/sort_selection.js";
import TableInsertUI from "./plugins/table_insert/table_insert_ui.js";
import TableToolbarDropdowns from "./plugins/table_toolbar_dropdowns.js";
import TriliumTableScroll from "./plugins/table_scroll.js";
@@ -132,6 +133,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
TableMove,
TablePasteRows,
TableSort,
+ SortSelection,
TableInsertUI,
TableToolbarDropdowns,
TriliumTableScroll,
diff --git a/packages/ckeditor5/src/plugins/command_list_dropdown.ts b/packages/ckeditor5/src/plugins/command_list_dropdown.ts
new file mode 100644
index 0000000000..9bdd86f748
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/command_list_dropdown.ts
@@ -0,0 +1,105 @@
+import {
+ addListToDropdown,
+ Collection,
+ createDropdown,
+ SplitButtonView,
+ SwitchButtonView,
+ UIModel
+} from "ckeditor5";
+import type {
+ ButtonExecuteEvent,
+ Command,
+ DropdownView,
+ ListDropdownItemDefinition,
+ Locale,
+ Plugin
+} from "ckeditor5";
+
+export type CommandListItem =
+ | { type: "button" | "switchbutton"; commandName: string; label: string }
+ | { type: "separator" };
+
+export interface CommandListDropdownOptions {
+ label: string;
+ icon: string;
+ items: CommandListItem[];
+ /** Makes the button a split button whose main part runs this command. */
+ splitButtonCommandName?: string;
+}
+
+/**
+ * Creates a dropdown listing `items`, each running its command and enabled while it is. The
+ * dropdown is enabled while one of the commands is. `plugin` owns the listeners.
+ */
+export function createCommandListDropdown(
+ plugin: Plugin,
+ locale: Locale,
+ options: CommandListDropdownOptions
+): DropdownView {
+ const editor = plugin.editor;
+ const { label, icon, items, splitButtonCommandName } = options;
+
+ const dropdownView = splitButtonCommandName
+ ? createDropdown(locale, SplitButtonView)
+ : createDropdown(locale);
+ dropdownView.buttonView.set({ label, icon, tooltip: true });
+
+ const commands: Command[] = [];
+ const definitions = new Collection<ListDropdownItemDefinition>();
+ for (const item of items) {
+ if (item.type === "separator") {
+ // A new object each time: `Collection#add()` gives it an `id`.
+ definitions.add({ type: "separator" });
+ continue;
+ }
+
+ // Skips an item whose command is not registered, e.g. after an upstream rename.
+ const command = editor.commands.get(item.commandName);
+ if (!command) {
+ continue;
+ }
+ commands.push(command);
+
+ const model = new UIModel({
+ commandName: item.commandName,
+ label: item.label,
+ withText: true
+ });
+ model.bind("isEnabled").to(command);
+ if (item.type === "switchbutton") {
+ model.bind("isOn").to(command, "value");
+ }
+ definitions.add({ type: item.type, model });
+ }
+ addListToDropdown(dropdownView, definitions);
+
+ dropdownView.bind("isEnabled").toMany(commands, "isEnabled",
+ (...areEnabled) => areEnabled.some((isEnabled) => isEnabled));
+
+ if (splitButtonCommandName) {
+ plugin.listenTo(dropdownView.buttonView, "execute", () => {
+ editor.execute(splitButtonCommandName);
+ editor.editing.view.focus();
+ });
+ }
+ plugin.listenTo<ButtonExecuteEvent>(dropdownView, "execute", (evt) => {
+ const source = evt.source as { commandName: string };
+ editor.execute(source.commandName);
+ // A switch keeps the dropdown open, so the focus stays in the list.
+ if (!(source instanceof SwitchButtonView)) {
+ editor.editing.view.focus();
+ }
+ });
+
+ return dropdownView;
+}
+
+export const SEPARATOR_ITEM: CommandListItem = { type: "separator" };
+
+export function buttonItem(commandName: string, label: string): CommandListItem {
+ return { type: "button", commandName, label };
+}
+
+export function switchItem(commandName: string, label: string): CommandListItem {
+ return { type: "switchbutton", commandName, label };
+}
diff --git a/packages/ckeditor5/src/plugins/sort_selection/sort_runs.spec.ts b/packages/ckeditor5/src/plugins/sort_selection/sort_runs.spec.ts
new file mode 100644
index 0000000000..a3b437c538
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/sort_selection/sort_runs.spec.ts
@@ -0,0 +1,105 @@
+import {
+ _setModelData as setModelData,
+ BlockQuote,
+ Essentials,
+ Heading,
+ HorizontalLine,
+ ImageBlock,
+ ImageCaption,
+ Paragraph,
+ Table
+} from "ckeditor5";
+import type { ClassicEditor, ModelElement } from "ckeditor5";
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { createTestEditor } from "../../../test/editor-kit.js";
+import CollapsibleEditing from "../collapsible/collapsible_editing.js";
+import { blockText, sortRuns, unitText } from "./sort_runs.js";
+
+describe("sort_runs", () => {
+ let editor: ClassicEditor;
+
+ beforeEach(async () => {
+ editor = await createTestEditor([
+ Essentials, Paragraph, Heading, BlockQuote, Table, ImageBlock, ImageCaption,
+ HorizontalLine, CollapsibleEditing
+ ], { language: { content: "en" } });
+ });
+
+ function rootChildren(): ModelElement[] {
+ return Array.from(editor.model.document.getRoot()?.getChildren() ?? []) as ModelElement[];
+ }
+
+ function texts(): string[] {
+ return rootChildren().map((child) => blockText(editor.model, child));
+ }
+
+ function runsOf(children: ModelElement[]) {
+ return children.map((child) => ({
+ first: child,
+ last: child,
+ text: unitText(editor.model, child)
+ }));
+ }
+
+ it("reads a block by the first element in it that holds text", () => {
+ setModelData(editor.model,
+ "<paragraph>a<softBreak></softBreak>b</paragraph>"
+ + "<heading2>head</heading2>"
+ + "<blockQuote><paragraph>quote</paragraph><paragraph>more</paragraph></blockQuote>"
+ + "<details><summary>title</summary><paragraph>body</paragraph></details>"
+ + "<table><tableRow><tableCell><paragraph>cell</paragraph></tableCell>"
+ + "<tableCell><paragraph>next</paragraph></tableCell></tableRow></table>"
+ + '<imageBlock src="a.png"><caption>caption</caption></imageBlock>'
+ + '<imageBlock src="b.png"></imageBlock>'
+ + "<horizontalLine></horizontalLine>");
+
+ expect(rootChildren().map((child) => unitText(editor.model, child))).toEqual([
+ "a b", "head", "quote", "title", "cell", "caption", "", ""
+ ]);
+ });
+
+ it("moves only the runs that are out of place, in one change", () => {
+ setModelData(editor.model,
+ "<paragraph>b</paragraph><paragraph>a</paragraph><paragraph>c</paragraph>");
+ const moves: string[] = [];
+ editor.model.on("applyOperation", (_evt, [ operation ]) => {
+ moves.push(operation.type);
+ });
+ const version = editor.model.document.version;
+
+ expect(sortRuns(editor, runsOf(rootChildren()), false)).toBe(true);
+ expect(texts()).toEqual([ "a", "b", "c" ]);
+ expect(moves).toEqual([ "move" ]);
+ expect(editor.model.document.version).toBe(version + 1);
+ });
+
+ it("moves a run of several nodes as one and runs the callback in the same change", () => {
+ setModelData(editor.model,
+ "<paragraph>b</paragraph><paragraph>b2</paragraph><paragraph>a</paragraph>");
+ const [ b, b2, a ] = rootChildren();
+ let changes = 0;
+ editor.model.document.on("change", () => changes++);
+
+ const isMoved = sortRuns(editor, [
+ { first: b, last: b2, text: "b" },
+ { first: a, last: a, text: "a" }
+ ], false, (writer) => writer.setSelection(a, "in"));
+
+ expect(isMoved).toBe(true);
+ expect(texts()).toEqual([ "a", "b", "b2" ]);
+ expect(editor.model.document.selection.getFirstPosition()?.parent).toBe(a);
+ expect(changes).toBe(1);
+ });
+
+ it("writes nothing when the runs are already in order", () => {
+ setModelData(editor.model, "<paragraph>a</paragraph><paragraph>b</paragraph>");
+ const version = editor.model.document.version;
+
+ expect(sortRuns(editor, runsOf(rootChildren()), false)).toBe(false);
+ expect(editor.model.document.version).toBe(version);
+
+ expect(sortRuns(editor, runsOf(rootChildren()), true)).toBe(true);
+ expect(texts()).toEqual([ "b", "a" ]);
+ });
+});
diff --git a/packages/ckeditor5/src/plugins/sort_selection/sort_runs.ts b/packages/ckeditor5/src/plugins/sort_selection/sort_runs.ts
new file mode 100644
index 0000000000..6a4aaf57a6
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/sort_selection/sort_runs.ts
@@ -0,0 +1,79 @@
+import { autoSort } from "@triliumnext/commons";
+import type { Editor, Model, ModelElement, ModelNode, ModelWriter } from "ckeditor5";
+
+/** Sibling nodes from `first` to `last` that move as one, and the text they sort by. */
+export interface SortRun {
+ first: ModelNode;
+ last: ModelNode;
+ text: string;
+}
+
+/**
+ * Sorts `runs` with `autoSort` in the content language of the editor, and moves them into the new
+ * order in one undo step. The runs must be contiguous and in document order. Writes nothing when
+ * the order does not change, and returns whether anything moved. `afterMove` runs in the same
+ * change, with the runs in their new order.
+ */
+export function sortRuns(
+ editor: Editor,
+ runs: SortRun[],
+ isDescending: boolean,
+ afterMove?: (writer: ModelWriter, sorted: SortRun[]) => void
+): boolean {
+ const sorted = autoSort(runs, (run) => run.text, {
+ locale: editor.locale.contentLanguage,
+ isDescending,
+ dateFormats: editor.config.get("autoSort")?.dateFormats
+ });
+ if (sorted.every((run, index) => run === runs[index])) {
+ return false;
+ }
+
+ editor.model.change((writer) => {
+ const regionStart = runs[0].first;
+ let previous: SortRun | null = null;
+ for (const run of sorted) {
+ // The previous move shifts the nodes after it, so `insertAt` is read inside the loop.
+ const insertAt = previous
+ ? writer.createPositionAfter(previous.last)
+ : writer.createPositionBefore(regionStart);
+ // `writer.move()` skips a run that is already at `insertAt`.
+ writer.move(writer.createRange(
+ writer.createPositionBefore(run.first),
+ writer.createPositionAfter(run.last)), insertAt);
+ previous = run;
+ }
+ afterMove?.(writer, sorted);
+ });
+ return true;
+}
+
+/**
+ * The plain text of `element`. Elements inside it, such as paragraphs and line breaks, are
+ * spaces.
+ */
+export function blockText(model: Model, element: ModelElement): string {
+ let text = "";
+ for (const item of model.createRangeIn(element).getItems()) {
+ text += item.is("$textProxy") ? item.data : " ";
+ }
+ return text;
+}
+
+/**
+ * The text a block sorts by: the text of the first element in it, itself included, that can hold
+ * text. A collapsible sorts by its title, a quote by its first paragraph, an image by its caption.
+ * A block with no such element sorts as empty.
+ */
+export function unitText(model: Model, block: ModelElement): string {
+ if (model.schema.checkChild(block, "$text")) {
+ return blockText(model, block);
+ }
+
+ for (const item of model.createRangeIn(block).getItems()) {
+ if (item.is("element") && model.schema.checkChild(item, "$text")) {
+ return blockText(model, item);
+ }
+ }
+ return "";
+}
diff --git a/packages/ckeditor5/src/plugins/sort_selection/sort_selection.spec.ts b/packages/ckeditor5/src/plugins/sort_selection/sort_selection.spec.ts
new file mode 100644
index 0000000000..c06a65cd6d
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/sort_selection/sort_selection.spec.ts
@@ -0,0 +1,318 @@
+import {
+ _getModelData as getModelData,
+ _setModelData as setModelData,
+ BlockQuote,
+ Essentials,
+ Heading,
+ List,
+ ListItemView,
+ Paragraph,
+ SplitButtonView,
+ Table,
+ TodoList
+} from "ckeditor5";
+import type { ButtonView, ClassicEditor, DropdownView, ModelElement } from "ckeditor5";
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { createTestEditor } from "../../../test/editor-kit.js";
+import { modelTable, selectCells } from "../../../test/table-kit.js";
+import CollapsibleEditing from "../collapsible/collapsible_editing.js";
+import MulticolumnEditing from "../multicolumn/multicolumn_editing.js";
+import SortSelection from "./sort_selection.js";
+
+const ASCENDING = "triliumSortSelectionAscending";
+const DESCENDING = "triliumSortSelectionDescending";
+
+describe("SortSelection", () => {
+ let editor: ClassicEditor;
+
+ beforeEach(async () => {
+ editor = await createTestEditor([
+ Essentials, Paragraph, Heading, List, TodoList, BlockQuote, Table, CollapsibleEditing,
+ MulticolumnEditing, SortSelection
+ ], { language: { content: "en" }, toolbar: [ "sortSelection" ] });
+ });
+
+ function sort(name = ASCENDING) {
+ editor.execute(name);
+ }
+
+ function isEnabled(name = ASCENDING) {
+ return editor.commands.get(name)?.isEnabled === true;
+ }
+
+ function kind() {
+ return editor.commands.get(ASCENDING)?.value ?? null;
+ }
+
+ /** The root's blocks as lines: a list block indented by its level, else its name and text. */
+ function outline(): string[] {
+ const model = editor.model;
+ return Array.from(model.document.getRoot()?.getChildren() ?? [], (node) => {
+ const element = node as ModelElement;
+ let text = "";
+ for (const item of model.createRangeIn(element).getItems()) {
+ text += item.is("$textProxy") ? item.data : "";
+ }
+ const indent = element.getAttribute("listIndent");
+ return typeof indent === "number"
+ ? `${" ".repeat(indent)}* ${text}`
+ : `${element.name} ${text}`;
+ });
+ }
+
+ describe("in a list", () => {
+ it("sorts the items at the level of the caret, each with its nested items", () => {
+ setModelData(editor.model,
+ item("b", "b") + item("b2", "b2", 1) + item("b1", "b1", 1)
+ + item("c", "c[]") + item("a", "a"));
+ expect(kind()).toBe("listItems");
+
+ sort();
+ expect(outline()).toEqual([ "* a", "* b", " * b2", " * b1", "* c" ]);
+
+ sort(DESCENDING);
+ expect(outline()).toEqual([ "* c", "* b", " * b2", " * b1", "* a" ]);
+ });
+
+ it("sorts a nested list alone, leaving its parent list in place", () => {
+ setModelData(editor.model,
+ item("z", "z") + item("b2", "b2", 1) + item("b1", "b1[]", 1) + item("a", "a"));
+ sort();
+ expect(outline()).toEqual([ "* z", " * b1", " * b2", "* a" ]);
+ });
+
+ it("sorts only the selected items of a range", () => {
+ setModelData(editor.model,
+ item("d", "d") + item("c", "[c") + item("b", "b]") + item("a", "a"));
+ sort();
+ expect(outline()).toEqual([ "* d", "* b", "* c", "* a" ]);
+ });
+
+ it("sorts the items at the lowest level of a range starting in a nested item", () => {
+ setModelData(editor.model,
+ item("y", "y") + item("x", "x") + item("x1", "[x1", 1) + item("w", "w]"));
+ sort();
+ expect(outline()).toEqual([ "* y", "* w", "* x", " * x1" ]);
+ });
+
+ it("keeps the blocks of an item and its to-do state together", () => {
+ setModelData(editor.model,
+ item("b", "b", 0, "todo", ' todoListChecked="true"')
+ + item("b", "b more", 0, "todo", ' todoListChecked="true"')
+ + item("a", "a[]", 0, "todo"));
+ sort();
+ expect(outline()).toEqual([ "* a", "* b", "* b more" ]);
+ const root = editor.model.document.getRoot();
+ expect(root?.getChild(1)?.getAttribute("todoListChecked")).toBe(true);
+ expect(root?.getChild(2)?.getAttribute("todoListChecked")).toBe(true);
+ expect(root?.getChild(0)?.hasAttribute("todoListChecked")).toBe(false);
+ });
+
+ it("is disabled for a range across two lists of different kinds", () => {
+ setModelData(editor.model,
+ item("b", "[b") + item("a", "a]", 0, "numbered"));
+ expect(isEnabled()).toBe(false);
+ expect(kind()).toBeNull();
+ });
+
+ it("is disabled in a list of one item, and for items in different parents", () => {
+ setModelData(editor.model, item("a", "a[]") + "<paragraph>b</paragraph>");
+ expect(isEnabled()).toBe(false);
+
+ setModelData(editor.model,
+ item("b", "[b") + "<blockQuote>" + item("a", "a]") + "</blockQuote>");
+ expect(isEnabled()).toBe(false);
+ });
+
+ it("writes nothing when the items are already in order", () => {
+ setModelData(editor.model, item("a", "a[]") + item("b", "b"));
+ const version = editor.model.document.version;
+ sort();
+ expect(editor.model.document.version).toBe(version);
+ });
+ });
+
+ describe("on sibling blocks", () => {
+ it("sorts the selected blocks in one undo step and selects them", () => {
+ setModelData(editor.model,
+ "<paragraph>[c</paragraph><heading2>b</heading2><paragraph>a]</paragraph>");
+ expect(kind()).toBe("blocks");
+
+ sort();
+ expect(getModelData(editor.model))
+ .toBe("<paragraph>[a</paragraph><heading2>b</heading2><paragraph>c]</paragraph>");
+
+ editor.execute("undo");
+ expect(outline()).toEqual([ "paragraph c", "heading2 b", "paragraph a" ]);
+ });
+
+ it("moves a container or an object whole, sorted by its first text", () => {
+ setModelData(editor.model,
+ "<paragraph>[z</paragraph>"
+ + "<blockQuote><paragraph>m</paragraph><paragraph>y</paragraph></blockQuote>"
+ + "<details><summary>b</summary><paragraph>x</paragraph></details>"
+ + "<table><tableRow><tableCell><paragraph>c</paragraph></tableCell></tableRow>"
+ + "</table>"
+ + "<paragraph>a]</paragraph>");
+ sort();
+ expect(outline()).toEqual(
+ [ "paragraph a", "details bx", "table c", "blockQuote my", "paragraph z" ]);
+ });
+
+ it("sorts collapsibles by their titles, and nothing from a title into its body", () => {
+ setModelData(editor.model,
+ "<details><summary>[b</summary><paragraph>x</paragraph></details>"
+ + "<details><summary>a]</summary><paragraph>y</paragraph></details>");
+ sort();
+ expect(outline()).toEqual([ "details ay", "details bx" ]);
+
+ setModelData(editor.model,
+ "<details><summary>[b</summary><paragraph>a]</paragraph></details>");
+ expect(isEnabled()).toBe(false);
+ });
+
+ it("leaves columns in place, as a range across them selects the layout", () => {
+ setModelData(editor.model,
+ "<multicolumnLayout columnRatios=\"1-1\">"
+ + "<multicolumnColumn><paragraph>[b</paragraph></multicolumnColumn>"
+ + "<multicolumnColumn><paragraph>a]</paragraph></multicolumnColumn>"
+ + "</multicolumnLayout>");
+ expect(isEnabled()).toBe(false);
+
+ setModelData(editor.model,
+ "<multicolumnLayout columnRatios=\"1-1\">"
+ + "<multicolumnColumn><paragraph>[b</paragraph><paragraph>a]</paragraph>"
+ + "</multicolumnColumn><multicolumnColumn><paragraph>z</paragraph>"
+ + "</multicolumnColumn></multicolumnLayout>");
+ sort();
+ expect(outline()).toEqual([ "multicolumnLayout abz" ]);
+ });
+
+ it("sorts the paragraphs of a range inside a table cell, not the rows", () => {
+ setModelData(editor.model,
+ "<table><tableRow><tableCell><paragraph>[b</paragraph><paragraph>a]</paragraph>"
+ + "</tableCell></tableRow><tableRow><tableCell><paragraph>0</paragraph>"
+ + "</tableCell></tableRow></table>");
+ expect(kind()).toBe("blocks");
+ sort();
+ expect(outline()).toEqual([ "table ab0" ]);
+ });
+
+ it("is disabled for a caret, a range in one block and a range mixing a list", () => {
+ setModelData(editor.model, "<paragraph>b[]</paragraph><paragraph>a</paragraph>");
+ expect(isEnabled()).toBe(false);
+
+ setModelData(editor.model, "<paragraph>[b]</paragraph><paragraph>a</paragraph>");
+ expect(isEnabled()).toBe(false);
+
+ setModelData(editor.model, "<paragraph>[b</paragraph>" + item("a", "a]"));
+ expect(isEnabled()).toBe(false);
+ });
+ });
+
+ describe("in a table", () => {
+ const table = modelTable([ [ "h" ], [ "b[]" ], [ "a" ] ], 'headingRows="1"');
+
+ it("sorts the body rows by the column of the caret, as the table command does", () => {
+ // Enabled in the same change that made the table sortable, so this command refreshes
+ // after the table command.
+ setModelData(editor.model, table);
+ expect(isEnabled()).toBe(true);
+ expect(kind()).toBe("rows");
+
+ sort();
+ expect(cellTexts()).toEqual([ "h", "a", "b" ]);
+ sort(DESCENDING);
+ expect(cellTexts()).toEqual([ "h", "b", "a" ]);
+ });
+
+ it("sorts rows for cells selected down one column, and nothing across two", () => {
+ setModelData(editor.model,
+ modelTable([ [ "c", "1" ], [ "b", "2" ], [ "a", "3" ] ]));
+ selectCells(editor, [ 0, 0 ], [ 1, 0 ]);
+ expect(kind()).toBe("rows");
+ sort();
+ expect(cellTexts()).toEqual([ "b", "2", "c", "1", "a", "3" ]);
+
+ selectCells(editor, [ 0, 0 ], [ 1, 1 ]);
+ expect(isEnabled()).toBe(false);
+ });
+
+ it("sorts a list in a cell instead of the rows", () => {
+ setModelData(editor.model,
+ "<table><tableRow><tableCell>" + item("b", "b[]") + item("a", "a")
+ + "</tableCell></tableRow><tableRow><tableCell><paragraph>0</paragraph>"
+ + "</tableCell></tableRow></table>");
+ expect(kind()).toBe("listItems");
+ sort();
+ expect(cellTexts()).toEqual([ "ab", "0" ]);
+ });
+
+ it("is disabled in read-only mode", () => {
+ setModelData(editor.model, table);
+ editor.enableReadOnlyMode("spec");
+ expect(isEnabled()).toBe(false);
+ expect(isEnabled(DESCENDING)).toBe(false);
+ });
+
+ it("does nothing when executed with nothing to sort", () => {
+ setModelData(editor.model, "<paragraph>b[]</paragraph><paragraph>a</paragraph>");
+ const command = editor.commands.get(ASCENDING);
+ if (!command) {
+ throw new Error("Command not registered.");
+ }
+ const version = editor.model.document.version;
+ command.isEnabled = true;
+ command.execute();
+ expect(editor.model.document.version).toBe(version);
+ });
+ });
+
+ describe("the toolbar button", () => {
+ it("is a split button that sorts ascending, with both directions in its list", () => {
+ setModelData(editor.model,
+ "<paragraph>[b</paragraph><paragraph>c</paragraph><paragraph>a]</paragraph>");
+ const dropdown = editor.ui.view.toolbar.items.get(0) as DropdownView;
+ expect(dropdown.buttonView).toBeInstanceOf(SplitButtonView);
+ expect(dropdown.buttonView.label).toBe("Sort");
+ expect(dropdown.isEnabled).toBe(true);
+
+ dropdown.buttonView.fire("execute");
+ expect(outline()).toEqual([ "paragraph a", "paragraph b", "paragraph c" ]);
+
+ dropdown.isOpen = true;
+ const buttons = Array.from(dropdown.listView?.items ?? [], (listItem) =>
+ (listItem as ListItemView).children.first as ButtonView);
+ expect(buttons.map((button) => button.label)).toEqual([ "Ascending", "Descending" ]);
+ buttons[1].fire("execute");
+ expect(outline()).toEqual([ "paragraph c", "paragraph b", "paragraph a" ]);
+
+ setModelData(editor.model, "<paragraph>a[]</paragraph>");
+ expect(dropdown.isEnabled).toBe(false);
+ });
+ });
+
+ function cellTexts(): string[] {
+ const texts: string[] = [];
+ const root = editor.model.document.getRoot();
+ if (!root) {
+ return texts;
+ }
+ for (const node of editor.model.createRangeIn(root).getItems()) {
+ if (node.is("element", "tableCell")) {
+ let text = "";
+ for (const child of editor.model.createRangeIn(node).getItems()) {
+ text += child.is("$textProxy") ? child.data : "";
+ }
+ texts.push(text);
+ }
+ }
+ return texts;
+ }
+});
+
+function item(id: string, text: string, indent = 0, type = "bulleted", extra = "") {
+ return `<paragraph listIndent="${indent}" listItemId="${id}" listType="${type}"${extra}>`
+ + `${text}</paragraph>`;
+}
diff --git a/packages/ckeditor5/src/plugins/sort_selection/sort_selection.ts b/packages/ckeditor5/src/plugins/sort_selection/sort_selection.ts
new file mode 100644
index 0000000000..632074d3bb
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/sort_selection/sort_selection.ts
@@ -0,0 +1,102 @@
+import bxSortAlt2 from "boxicons/svg/regular/bx-sort-alt-2.svg?raw";
+import { Command, Plugin } from "ckeditor5";
+import type { Editor } from "ckeditor5";
+
+import { buttonItem, createCommandListDropdown } from "../command_list_dropdown.js";
+import TableSort from "../table_sort.js";
+import { sortRuns } from "./sort_runs.js";
+import { resolveSortTarget, TABLE_SORT_COMMANDS } from "./sort_targets.js";
+import type { SortTargetKind } from "./sort_targets.js";
+
+/**
+ * Sorts what the selection is in with `autoSort`: the items of a list, sibling blocks, or the rows
+ * of a table through `TableSort`. Adds the `sortSelection` split button, whose main part sorts in
+ * ascending order.
+ */
+export default class SortSelection extends Plugin {
+
+ static get requires() {
+ // CKEditor loads `TableSort` first, so its commands refresh before these ones read them.
+ return [ TableSort ] as const;
+ }
+
+ static get pluginName() {
+ return "SortSelection" as const;
+ }
+
+ init() {
+ const editor = this.editor;
+ const t = editor.t;
+ editor.commands.add("triliumSortSelectionAscending",
+ new SortSelectionCommand(editor, false));
+ editor.commands.add("triliumSortSelectionDescending",
+ new SortSelectionCommand(editor, true));
+
+ editor.ui.componentFactory.add("sortSelection", (locale) =>
+ createCommandListDropdown(this, locale, {
+ label: t("Sort"),
+ icon: bxSortAlt2,
+ splitButtonCommandName: "triliumSortSelectionAscending",
+ items: [
+ buttonItem("triliumSortSelectionAscending", t("Ascending")),
+ buttonItem("triliumSortSelectionDescending", t("Descending"))
+ ]
+ }));
+ }
+
+}
+
+export class SortSelectionCommand extends Command {
+
+ /** What a sort reorders, or `null` while the command is disabled. */
+ declare value: SortTargetKind | null;
+
+ private readonly isDescending: boolean;
+
+ constructor(editor: Editor, isDescending: boolean) {
+ super(editor);
+ this.isDescending = isDescending;
+ }
+
+ override refresh() {
+ const target = resolveSortTarget(this.editor);
+ this.value = target?.kind ?? null;
+ this.isEnabled = target !== null;
+ }
+
+ override execute() {
+ const editor = this.editor;
+ const target = resolveSortTarget(editor);
+ if (!target) {
+ return;
+ }
+ if (target.kind === "rows") {
+ editor.execute(this.isDescending
+ ? TABLE_SORT_COMMANDS.descending
+ : TABLE_SORT_COMMANDS.ascending);
+ return;
+ }
+
+ // A caret moves with its block. A range is set over the sorted runs, as its ends moved.
+ const isRange = !editor.model.document.selection.isCollapsed;
+ sortRuns(editor, target.runs, this.isDescending, (writer, sorted) => {
+ if (isRange) {
+ writer.setSelection(writer.createRange(
+ writer.createPositionBefore(sorted[0].first),
+ writer.createPositionAfter(sorted[sorted.length - 1].last)));
+ }
+ });
+ }
+
+}
+
+declare module "ckeditor5" {
+ interface PluginsMap {
+ [SortSelection.pluginName]: SortSelection;
+ }
+
+ interface CommandsMap {
+ triliumSortSelectionAscending: SortSelectionCommand;
+ triliumSortSelectionDescending: SortSelectionCommand;
+ }
+}
diff --git a/packages/ckeditor5/src/plugins/sort_selection/sort_targets.ts b/packages/ckeditor5/src/plugins/sort_selection/sort_targets.ts
new file mode 100644
index 0000000000..aaa6dfea5e
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/sort_selection/sort_targets.ts
@@ -0,0 +1,151 @@
+import {
+ _getAllListItemBlocks as getAllListItemBlocks,
+ _getListItems as getListItems,
+ _isFirstBlockOfListItem as isFirstBlockOfListItem,
+ _isListItemBlock as isListItemBlock,
+ TableUtils
+} from "ckeditor5";
+import type { _ListElement as ListElement, Editor, Model, ModelElement } from "ckeditor5";
+
+import type { SortRun } from "./sort_runs.js";
+import { unitText } from "./sort_runs.js";
+
+/** What a sort of the selection reorders. */
+export type SortTargetKind = "listItems" | "blocks" | "rows";
+
+export type SortTarget =
+ | { kind: "listItems" | "blocks"; runs: SortRun[] }
+ | { kind: "rows" };
+
+/** The table commands that a sort of rows runs. */
+export const TABLE_SORT_COMMANDS = {
+ ascending: "triliumSortTableRowsAscending",
+ descending: "triliumSortTableRowsDescending"
+} as const;
+
+/**
+ * What a sort of the current selection reorders, or `null` when nothing can be sorted. The
+ * innermost structure is sorted: in a table cell, a list or several selected blocks are sorted,
+ * and a caret elsewhere in the cell sorts the rows.
+ */
+export function resolveSortTarget(editor: Editor): SortTarget | null {
+ const model = editor.model;
+ const selection = model.document.selection;
+ const tableUtils = editor.plugins.get(TableUtils);
+
+ if (tableUtils.getSelectedTableCells(selection).length) {
+ return getRowsTarget(editor);
+ }
+
+ const blocks = Array.from(selection.getSelectedBlocks());
+ const isBlockRange = !selection.isCollapsed && blocks.length > 1;
+ return getListTarget(model, blocks)
+ ?? (isBlockRange ? getBlocksTarget(model, blocks[0], blocks[blocks.length - 1]) : null)
+ ?? (tableUtils.getSelectionAffectedTableCells(selection).length
+ ? getRowsTarget(editor)
+ : null);
+}
+
+function getRowsTarget(editor: Editor): SortTarget | null {
+ return editor.commands.get(TABLE_SORT_COMMANDS.ascending)?.isEnabled ? { kind: "rows" } : null;
+}
+
+/**
+ * The items of the list at the lowest level of the selected list blocks. A caret, or a selection
+ * inside one item, sorts every item of its list at that level. Each item moves with its nested
+ * items, which are not sorted.
+ */
+function getListTarget(model: Model, blocks: ModelElement[]): SortTarget | null {
+ const listBlocks = blocks.filter(isListItemBlock);
+ if (!listBlocks.length || listBlocks.length < blocks.length) {
+ return null;
+ }
+
+ const level = Math.min(...listBlocks.map(getIndent));
+ const firstItem = getAncestorItem(listBlocks[0], level);
+ const lastItem = getAncestorItem(listBlocks[listBlocks.length - 1], level);
+ const firstId = firstItem.getAttribute("listItemId");
+ const lastId = lastItem.getAttribute("listItemId");
+ const heads = getListItems(firstItem).filter((block) => isFirstBlockOfListItem(block));
+
+ let selected = heads;
+ if (firstId !== lastId) {
+ const first = heads.findIndex((head) => head.getAttribute("listItemId") === firstId);
+ const last = heads.findIndex((head) => head.getAttribute("listItemId") === lastId);
+ // `slice()` returns nothing when the last item is in another list, such as a numbered
+ // list after a bulleted one or a list in a quote.
+ selected = heads.slice(first, last + 1);
+ }
+
+ if (selected.length < 2) {
+ return null;
+ }
+ return {
+ kind: "listItems",
+ runs: selected.map((head) => {
+ const itemBlocks = getAllListItemBlocks(head, { higherIndent: true });
+ return {
+ first: head,
+ last: itemBlocks[itemBlocks.length - 1],
+ text: unitText(model, head)
+ };
+ })
+ };
+}
+
+/**
+ * The siblings from the one holding `firstBlock` to the one holding `lastBlock`. A collapsible's
+ * title is replaced by the collapsible, as in the block moves. Not sortable when one of them is a
+ * list block.
+ */
+function getBlocksTarget(
+ model: Model,
+ firstBlock: ModelElement,
+ lastBlock: ModelElement
+): SortTarget | null {
+ // Root first, so the first ancestors that differ are two siblings.
+ const firstPath = getSortableBlock(firstBlock).getAncestors({ includeSelf: true });
+ const lastPath = getSortableBlock(lastBlock).getAncestors({ includeSelf: true });
+ const depth = firstPath.findIndex((ancestor, index) => ancestor !== lastPath[index]);
+ // One block holds the other.
+ if (depth < 0 || depth >= lastPath.length) {
+ return null;
+ }
+
+ // Below the root, every ancestor is an element.
+ const start = firstPath[depth] as ModelElement;
+ const end = lastPath[depth] as ModelElement;
+
+ const units = [ start ];
+ while (units[units.length - 1] !== end) {
+ // The children of a parent of blocks are elements.
+ units.push(units[units.length - 1].nextSibling as ModelElement);
+ }
+ if (units.some((unit) => isListItemBlock(unit))) {
+ return null;
+ }
+
+ return {
+ kind: "blocks",
+ runs: units.map((unit) => ({ first: unit, last: unit, text: unitText(model, unit) }))
+ };
+}
+
+/** `block`, or the collapsible whose title it is. */
+function getSortableBlock(block: ModelElement): ModelElement {
+ // A summary is only allowed in a collapsible.
+ return block.is("element", "summary") ? block.parent as ModelElement : block;
+}
+
+/** The item at `level` that holds `block`: itself, or the closest preceding item at that level. */
+function getAncestorItem(block: ListElement, level: number): ListElement {
+ let item = block;
+ while (getIndent(item) > level && isListItemBlock(item.previousSibling)) {
+ item = item.previousSibling;
+ }
+ return item;
+}
+
+function getIndent(block: ListElement): number {
+ return block.getAttribute("listIndent");
+}
diff --git a/packages/ckeditor5/src/plugins/table_sort.ts b/packages/ckeditor5/src/plugins/table_sort.ts
index d5c0bbcbc2..8ecd153122 100644
--- a/packages/ckeditor5/src/plugins/table_sort.ts
+++ b/packages/ckeditor5/src/plugins/table_sort.ts
@@ -1,4 +1,3 @@
-import { autoSort } from "@triliumnext/commons";
import {
Command,
Notification,
@@ -7,8 +6,9 @@ import {
TableUtils,
TableWalker
} from "ckeditor5";
-import type { Editor, Model, ModelElement, ModelPosition, ModelWriter } from "ckeditor5";
+import type { Editor, Model, ModelElement } from "ckeditor5";
+import { blockText, sortRuns } from "./sort_selection/sort_runs.js";
import { splitIntoGroups } from "./table_move/table_move_groups.js";
import type { IndexRange } from "./table_move/table_move_groups.js";
@@ -70,15 +70,14 @@ export class SortTableRowsCommand extends Command {
const editor = this.editor;
const groups = readGroups(editor.model, plan);
- const sorted = autoSort(groups, (group) => group.text, {
- locale: editor.locale.contentLanguage,
- isDescending: this.isDescending,
- dateFormats: editor.config.get("autoSort")?.dateFormats
- });
-
- if (sorted.some((group, index) => group !== groups[index])) {
- this.applyOrder(plan.table, plan.groups[0].first, sorted.map((group) => group.range));
- }
+ const rows = [...plan.table.getChildren()]
+ .filter((child): child is ModelElement => child.is("element", "tableRow"));
+ // The selection ranges are live, so they follow the moved rows.
+ sortRuns(editor, groups.map(({ range, text }) => ({
+ first: rows[range.first],
+ last: rows[range.last],
+ text
+ })), this.isDescending);
if (groups.some((group) => group.isTied)) {
const t = editor.t;
@@ -87,26 +86,6 @@ export class SortTableRowsCommand extends Command {
}
}
- /** Moves the row groups into `order`, starting at row `firstIndex`, in one undo step. */
- private applyOrder(table: ModelElement, firstIndex: number, order: IndexRange[]) {
- const model = this.editor.model;
- const rows = [...table.getChildren()]
- .filter((child): child is ModelElement => child.is("element", "tableRow"));
- const firstRow = rows[firstIndex];
-
- // The selection ranges are live, so they follow the moved rows.
- model.change((writer) => {
- let previous: ModelElement | null = null;
- for (const range of order) {
- const insertAt = previous
- ? writer.createPositionAfter(previous)
- : writer.createPositionBefore(firstRow);
- moveRows(writer, rows[range.first], rows[range.last], insertAt);
- previous = rows[range.last];
- }
- });
- }
-
private planSort(): SortPlan | null {
const editor = this.editor;
const tableUtils = editor.plugins.get(TableUtils);
@@ -161,32 +140,11 @@ function readGroups(model: Model, { table, column, groups }: SortPlan): RowGroup
return groups.map((range) => ({
range,
- text: cellText(model, cellsByRow[range.first]),
+ text: blockText(model, cellsByRow[range.first]),
isTied: new Set(cellsByRow.slice(range.first, range.last + 1)).size > 1
}));
}
-/** The plain text of a cell. Elements such as paragraphs and line breaks become spaces. */
-function cellText(model: Model, cell: ModelElement): string {
- let text = "";
- for (const item of model.createRangeIn(cell).getItems()) {
- text += item.is("$textProxy") ? item.data : " ";
- }
- return text;
-}
-
-function moveRows(
- writer: ModelWriter,
- firstRow: ModelElement,
- lastRow: ModelElement,
- insertAt: ModelPosition
-) {
- const start = writer.createPositionBefore(firstRow);
- if (!start.isEqual(insertAt)) {
- writer.move(writer.createRange(start, writer.createPositionAfter(lastRow)), insertAt);
- }
-}
-
declare module "ckeditor5" {
interface PluginsMap {
[TableSort.pluginName]: TableSort;
diff --git a/packages/ckeditor5/src/plugins/table_toolbar_dropdowns.ts b/packages/ckeditor5/src/plugins/table_toolbar_dropdowns.ts
index 7a0ad7edcf..2f98068d4a 100644
--- a/packages/ckeditor5/src/plugins/table_toolbar_dropdowns.ts
+++ b/packages/ckeditor5/src/plugins/table_toolbar_dropdowns.ts
@@ -1,24 +1,12 @@
import bxSortAlt2 from "boxicons/svg/regular/bx-sort-alt-2.svg?raw";
-import {
- addListToDropdown,
- Collection,
- createDropdown,
- IconTableColumn,
- IconTableMergeCell,
- Plugin,
- SplitButtonView,
- SwitchButtonView,
- Table,
- UIModel
-} from "ckeditor5";
-import type {
- ButtonExecuteEvent,
- Command,
- DropdownView,
- ListDropdownItemDefinition,
- Locale
-} from "ckeditor5";
+import { IconTableColumn, IconTableMergeCell, Plugin, Table } from "ckeditor5";
+import {
+ buttonItem,
+ createCommandListDropdown,
+ SEPARATOR_ITEM,
+ switchItem
+} from "./command_list_dropdown.js";
import TableContextMenu from "./table_context_menu.js";
import TableSort from "./table_sort.js";
@@ -48,7 +36,7 @@ export default class TableToolbarDropdowns extends Plugin {
const isContentLtr = editor.locale.contentLanguageDirection === "ltr";
// Replaces the dropdowns of `TableUI`, which `Table` initializes before this plugin.
- factory.add("tableColumn", (locale) => this.createDropdown(locale, {
+ factory.add("tableColumn", (locale) => createCommandListDropdown(this, locale, {
label: t("Column"),
icon: IconTableColumn,
items: [
@@ -65,7 +53,7 @@ export default class TableToolbarDropdowns extends Plugin {
]
}));
- factory.add("mergeTableCells", (locale) => this.createDropdown(locale, {
+ factory.add("mergeTableCells", (locale) => createCommandListDropdown(this, locale, {
label: t("Merge cells"),
icon: IconTableMergeCell,
splitButtonCommandName: "mergeTableCells",
@@ -84,7 +72,7 @@ export default class TableToolbarDropdowns extends Plugin {
]
}));
- factory.add("tableSort", (locale) => this.createDropdown(locale, {
+ factory.add("tableSort", (locale) => createCommandListDropdown(this, locale, {
label: t("Sort"),
icon: bxSortAlt2,
items: [
@@ -94,90 +82,6 @@ export default class TableToolbarDropdowns extends Plugin {
}));
}
- /**
- * Creates a dropdown listing `items`, enabled while one of their commands is. With
- * `splitButtonCommandName`, the main part of a split button runs that command.
- */
- private createDropdown(locale: Locale, options: TableDropdownOptions): DropdownView {
- const editor = this.editor;
- const { label, icon, items, splitButtonCommandName } = options;
-
- const dropdownView = splitButtonCommandName
- ? createDropdown(locale, SplitButtonView)
- : createDropdown(locale);
- dropdownView.buttonView.set({ label, icon, tooltip: true });
-
- const commands: Command[] = [];
- const definitions = new Collection<ListDropdownItemDefinition>();
- for (const item of items) {
- if (item.type === "separator") {
- // A new object each time: `Collection#add()` gives it an `id`.
- definitions.add({ type: "separator" });
- continue;
- }
-
- // Skips an item whose command is not registered, e.g. after an upstream rename.
- const command = editor.commands.get(item.commandName);
- if (!command) {
- continue;
- }
- commands.push(command);
-
- const model = new UIModel({
- commandName: item.commandName,
- label: item.label,
- withText: true
- });
- model.bind("isEnabled").to(command);
- if (item.type === "switchbutton") {
- model.bind("isOn").to(command, "value");
- }
- definitions.add({ type: item.type, model });
- }
- addListToDropdown(dropdownView, definitions);
-
- dropdownView.bind("isEnabled").toMany(commands, "isEnabled",
- (...areEnabled) => areEnabled.some((isEnabled) => isEnabled));
-
- if (splitButtonCommandName) {
- this.listenTo(dropdownView.buttonView, "execute", () => {
- editor.execute(splitButtonCommandName);
- editor.editing.view.focus();
- });
- }
- this.listenTo<ButtonExecuteEvent>(dropdownView, "execute", (evt) => {
- const source = evt.source as { commandName: string };
- editor.execute(source.commandName);
- // A switch keeps the dropdown open, so the focus stays in the list.
- if (!(source instanceof SwitchButtonView)) {
- editor.editing.view.focus();
- }
- });
-
- return dropdownView;
- }
-
-}
-
-type TableDropdownItem =
- | { type: "button" | "switchbutton"; commandName: string; label: string }
- | { type: "separator" };
-
-interface TableDropdownOptions {
- label: string;
- icon: string;
- items: TableDropdownItem[];
- splitButtonCommandName?: string;
-}
-
-const SEPARATOR_ITEM: TableDropdownItem = { type: "separator" };
-
-function buttonItem(commandName: string, label: string): TableDropdownItem {
- return { type: "button", commandName, label };
-}
-
-function switchItem(commandName: string, label: string): TableDropdownItem {
- return { type: "switchbutton", commandName, label };
}
declare module "ckeditor5" {