Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/links: use the new link dialog for inserting and editing web links

Adorian Doranb6fe68cfe66b
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 852ff9ba71..a77e0ce210 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -383,7 +383,7 @@ export type CommandMappings = {
showCheatsheet: CommandData;
showShortcutHints: CommandData;
showHelp: CommandData;
- addLinkToText: CommandData;
+ addLinkToText: CommandData & Pick<AddLinkOpts, "target">;
followLinkUnderCursor: CommandData;
insertDateTimeToText: CommandData;
pasteMarkdownIntoText: CommandData;
diff --git a/apps/client/src/widgets/dialogs/add_link.spec.tsx b/apps/client/src/widgets/dialogs/add_link.spec.tsx
index 844b4d4609..dc61116a0b 100644
--- a/apps/client/src/widgets/dialogs/add_link.spec.tsx
+++ b/apps/client/src/widgets/dialogs/add_link.spec.tsx
@@ -178,6 +178,24 @@ describe("AddLinkDialog", () => {
expect(current()).toBe("add_link.note");
});
+ it("opens a new link on the side asked for, and an edited one on its own side", async () => {
+ await open({ target: "url" });
+ expect(current()).toBe("add_link.web_link");
+ expect(field("url")?.value).toBe("");
+ expect(field("text")).not.toBeNull();
+
+ await open({ target: "url", text: "some words", hasSelection: true });
+ expect(current()).toBe("add_link.web_link");
+ expect(field("text")).toBeNull();
+ await type(field("url"), "example.com");
+ await submit();
+ expect(addLink)
+ .toHaveBeenLastCalledWith("https://example.com", "https://example.com", true);
+
+ await open({ target: "url", currentLink: { notePath: "root/abc" } });
+ expect(current()).toBe("add_link.note");
+ });
+
it("edits a link with its own text, keeping that text and its anchor", async () => {
const note = buildNote({ title: "Target", "#internalBookmark": "part" });
await open({
diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/add_link.tsx
index 6aac89f662..9a707e1fa0 100644
--- a/apps/client/src/widgets/dialogs/add_link.tsx
+++ b/apps/client/src/widgets/dialogs/add_link.tsx
@@ -23,7 +23,7 @@ import SegmentedChoice from "../react/SegmentedChoice";
type LinkType = "reference-link" | "external-link" | "hyper-link";
/** What the link points at: a note, or an address outside Trilium. */
-type LinkTarget = "note" | "url";
+export type LinkTarget = "note" | "url";
function findAnchorIds(content: string): string[] {
const re = /<a\b([^>]*)>(<\/a>)?/g;
@@ -72,6 +72,11 @@ export interface AddLinkOpts {
currentTitle?: string;
/** The anchor within the note that the link being edited points at. */
currentBookmark?: string;
+ /**
+ * The side a new link opens on, the note side by default. A selected URL opens on the web link
+ * side.
+ */
+ target?: LinkTarget;
/**
* Repoints a reference link to a missing note. The dialog is titled "Fix link", searches for
* `text`, and offers only notes, always as a reference link.
@@ -440,14 +445,16 @@ export default function AddLinkDialog() {
}
/**
- * The address the dialog opens on, on the web link side: the external link being edited, or a
- * selected text that is a URL. `null` opens it on the note side.
+ * The address the dialog opens on, on the web link side: the external link being edited, a
+ * selected text that is a URL, or an empty one for `target: "url"`. `null` opens it on the note
+ * side.
*/
function getInitialWebLink(opts: AddLinkOpts): string | null {
if (opts.fixLink) return null;
if (opts.currentLink) return opts.currentLink.externalLink ?? null;
const text = opts.text.trim();
- return opts.hasSelection && hasScheme(text) ? text : null;
+ if (opts.hasSelection && hasScheme(text)) return text;
+ return opts.target === "url" ? "" : null;
}
/** Whether `text` is a whole URL with a scheme, the way the note search tells URLs apart. */
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts b/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts
index 8e3be60087..fa3b3c04de 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts
@@ -482,4 +482,9 @@ describe("getAddLinkOpts", () => {
expect(api.addLink).toHaveBeenCalledExactlyOnceWith("https://example.com", "Example", true);
expect(api.updateLink).not.toHaveBeenCalled();
});
+
+ it("opens a new link on the side it is asked for", () => {
+ expect(getAddLinkOpts(createApi(null), ready, "url").target).toBe("url");
+ expect(getAddLinkOpts(createApi(null), ready).target).toBeUndefined();
+ });
});
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index a22f8d2a6a..6c7cf94f2e 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -12,7 +12,7 @@ import {
import { deferred, formatBlockRange, parseBlockRange } from "@triliumnext/commons";
import { useEffect, useRef, useState } from "preact/hooks";
-import appContext from "../../../components/app_context";
+import appContext, { type CommandListenerData } from "../../../components/app_context";
import { consumeBlockReference } from "../../../services/block_reference";
import { consumeBookmark } from "../../../services/bookmark_jump";
import dialog from "../../../services/dialog";
@@ -248,9 +248,9 @@ export default function EditableText({
};
useLegacyImperativeHandlers({
- addLinkToTextCommand() {
+ addLinkToTextCommand({ target }: CommandListenerData<"addLinkToText"> = {}) {
if (!editorApiRef.current) return;
- const opts = getAddLinkOpts(editorApiRef.current, waitForEditor);
+ const opts = getAddLinkOpts(editorApiRef.current, waitForEditor, target);
parentComponent?.triggerCommand("showAddLinkDialog", opts);
},
pasteMarkdownIntoTextCommand() {
@@ -560,9 +560,11 @@ export default function EditableText({
*/
/**
* What the Add link dialog opens on: the link around the caret, which saving rewrites, or a new
- * link at the selection.
+ * link at the selection, on the `target` side.
*/
-export function getAddLinkOpts(api: CKEditorApi, ready: () => Promise<unknown>): AddLinkOpts {
+export function getAddLinkOpts(
+ api: CKEditorApi, ready: () => Promise<unknown>, target?: AddLinkOpts["target"]
+): AddLinkOpts {
const currentLink = api.getCurrentLink();
if (currentLink) {
return {
@@ -580,6 +582,7 @@ export function getAddLinkOpts(api: CKEditorApi, ready: () => Promise<unknown>):
return {
text: api.getSelectedText(),
hasSelection: api.hasSelection(),
+ target,
async addLink(notePath, linkTitle, externalLink) {
await ready();
api.addLink(notePath, linkTitle, externalLink);
diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.ts
index fb8df557bc..6e6760459d 100644
--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts
@@ -410,8 +410,10 @@ describe("CK config - tables", () => {
it("hands the dialogs and cut to note of the editor to the app commands that do them", async () => {
const triggerHostCommand = vi.fn(async () => undefined);
const config = await buildConfig(baseOpts({ triggerHostCommand }));
+ await config.internalLink?.openDialog({ target: "url" });
+ expect(triggerHostCommand).toHaveBeenLastCalledWith("addLinkToText", { target: "url" });
+
const callbacks = [
- [ config.internalLink?.openDialog, "addLinkToText" ],
[ config.markdownImport?.open, "pasteMarkdownIntoText" ],
[ config.contentEmbed?.pickNote, "addIncludeNoteToText" ],
[ config.cutToNote?.cut, "cutIntoNote" ],
@@ -422,7 +424,7 @@ describe("CK config - tables", () => {
await callback?.();
expect(triggerHostCommand).toHaveBeenLastCalledWith(command);
}
- expect(triggerHostCommand).toHaveBeenCalledTimes(callbacks.length);
+ expect(triggerHostCommand).toHaveBeenCalledTimes(callbacks.length + 1);
});
it("shows the icon picker the editor asks for, and none without a host for it", async () => {
diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.ts
index 21931e1d1d..1717030078 100644
--- a/apps/client/src/widgets/type_widgets/text/config.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.ts
@@ -258,7 +258,11 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi
linkEmbed: buildLinkEmbedHost(opts.getNoteId),
getNoteId: opts.getNoteId,
attachmentUpload: buildAttachmentUploadHost(opts.getComponentId),
- internalLink: { openDialog: bindHostCommand(opts, "addLinkToText") },
+ internalLink: {
+ openDialog: async (options) => {
+ await opts.triggerHostCommand?.("addLinkToText", options);
+ }
+ },
childNote: buildChildNoteHost(() => opts.getChildNoteParent?.()),
markdownImport: { open: bindHostCommand(opts, "pasteMarkdownIntoText") },
inlineIcon: { showPicker: (request) => opts.showIconPicker?.(request) ?? null },
diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.json
index 77dcf26d22..17c0ed7dde 100644
--- a/apps/server/src/assets/help/help_content.json
+++ b/apps/server/src/assets/help/help_content.json
@@ -140,7 +140,7 @@
"_help_oiVPnW8QfnvS": "<h2>Trilium-specific shortcuts</h2><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Bring up inline formatting toolbar (arrow keys ←,→ to navigate, Enter to apply)</td><td>Alt+F10</td><td>⌥+F10</td></tr><tr><td>Bring up block formatting toolbar</td><td>Alt+F10</td><td>⌥+F10</td></tr><tr><td>Create <a href=\"#root/_help_QEAPj01N5f7w\">external link</a></td><td>Ctrl+K</td><td>⌘+K</td></tr><tr><td>Create <a href=\"#root/_help_QEAPj01N5f7w\">internal (note) link</a></td><td>Ctrl+L</td><td>⌘+L</td></tr><tr><td>Inserts current date and time at caret position</td><td>Alt+T</td><td>⌥+T</td></tr><tr><td>Increase paragraph indentation</td><td>Tab</td><td>⇥</td></tr><tr><td>Decrease paragraph indentation</td><td>Shift + Tab</td><td>⇧ + ⇥</td></tr><tr><td>Mark selected text as <a href=\"#root/_help_UYuUB1ZekNQU\">keyboard shortcut</a></td><td>Ctrl + Alt + K</td><td>⌘+ ⌥+ K</td></tr><tr><td>Insert&nbsp;<a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a></td><td>Ctrl + M</td><td>⌘+ M</td></tr><tr><td>Move blocks (lists, paragraphs, etc.) up, or in a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> the rows</td><td>Alt+↑</td><td>⌥+↑</td></tr><tr><td>Move blocks (lists, paragraphs, etc.) down, or in a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> the rows</td><td>Alt+↓</td><td>⌥+↓</td></tr><tr><td>Move the selected content to another column of a <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a></td><td>Ctrl+←, Ctrl+→, Ctrl+Shift+Home, Ctrl+Shift+End</td><td>⌘+←, ⌘+→, ⌘+⇧+Home, ⌘+⇧+End</td></tr><tr><td>Move the current column of a multicolumn layout</td><td>Ctrl+Alt+←, Ctrl+Alt+→, Ctrl+Alt+Home, Ctrl+Alt+End</td><td>⌘+⌥+←, ⌘+⌥+→, ⌘+⌥+Home, ⌘+⌥+End</td></tr><tr><td>Add a column after or before the current one in a multicolumn layout</td><td>Ctrl+Enter, Ctrl+Shift+Enter</td><td>⌘+Enter, ⌘+⇧+Enter</td></tr><tr><td>Move the selected content to another tab in <a class=\"reference-link\" href=\"#root/_help_EK2ckIZ74tbT\">Content tabs</a></td><td>Ctrl+←, Ctrl+→, Ctrl+Shift+Home, Ctrl+Shift+End</td><td>⌘+←, ⌘+→, ⌘+⇧+Home, ⌘+⇧+End</td></tr><tr><td>Move the current tab of a tabs block</td><td>Ctrl+Alt+←, Ctrl+Alt+→, Ctrl+Alt+Home, Ctrl+Alt+End</td><td>⌘+⌥+←, ⌘+⌥+→, ⌘+⌥+Home, ⌘+⌥+End</td></tr><tr><td>Add a tab after or before the current one in a tabs block</td><td>Ctrl+Enter, Ctrl+Shift+Enter</td><td>⌘+Enter, ⌘+⇧+Enter</td></tr></tbody></table></figure><h2>Common shortcuts</h2><aside class=\"admonition tip\"><p>This section of keyboard shortcuts presents a subset of the keyboard shortcuts as supported by the editor technology we are using,&nbsp;<a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>. The shortcuts were taken from the <a href=\"https://ckeditor.com/docs/ckeditor5/latest/features/accessibility.html#keyboard-shortcuts\">official documentation</a>. Note that not all the shortcuts in the original documentation are applicable (due to using a different configuration).</p></aside><h3>Content editing</h3><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Insert a hard break (a new paragraph)</td><td>Enter</td><td></td></tr><tr><td>Insert a soft break (a <code>&lt;br&gt;</code> element)</td><td>Shift+Enter</td><td>⇧Enter</td></tr><tr><td>Copy selected content</td><td>Ctrl+C</td><td>⌘C</td></tr><tr><td>Paste content</td><td>Ctrl+V</td><td>⌘V</td></tr><tr><td>Paste content as plain text</td><td>Ctrl+Shift+V</td><td>⌘⇧V</td></tr><tr><td>Undo</td><td>Ctrl+Z</td><td>⌘Z</td></tr><tr><td>Redo</td><td>Ctrl+Y, Ctrl+Shift+Z</td><td>⌘Y, ⌘⇧Z</td></tr><tr><td>Bold text</td><td>Ctrl+B</td><td>⌘B</td></tr><tr><td>Change text case</td><td>Shift+F3</td><td>⇧F3 (may require Fn)</td></tr><tr><td>Create link</td><td>Ctrl+K</td><td>⌘K</td></tr><tr><td>Move out of a link</td><td>←←, →→</td><td></td></tr><tr><td>Move out of an inline code style</td><td>←←, →→</td><td></td></tr><tr><td>Select all</td><td>Ctrl+A</td><td>⌘A</td></tr><tr><td>Find in the document</td><td>Ctrl+F</td><td>⌘F</td></tr><tr><td>Copy text formatting</td><td>Ctrl+Shift+C</td><td>⌘⇧C</td></tr><tr><td>Paste text formatting</td><td>Ctrl+Shift+V</td><td>⌘⇧V</td></tr><tr><td>Italic text</td><td>Ctrl+I</td><td>⌘I</td></tr><tr><td>Strikethrough text</td><td>Ctrl+Shift+X</td><td>⌘⇧X</td></tr><tr><td>Underline text</td><td>Ctrl+U</td><td>⌘U</td></tr><tr><td>Revert autoformatting action</td><td>Backspace</td><td></td></tr></tbody></table></figure><h3>Interacting with blocks</h3><p>Blocks are images, tables, blockquotes, annotations.</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Insert a new paragraph directly after a widget</td><td>Enter</td><td></td></tr><tr><td>Insert a new paragraph directly before a widget</td><td>Shift+Enter</td><td>⇧Enter</td></tr><tr><td>Move the caret to allow typing directly before a widget</td><td>↑, ←</td><td></td></tr><tr><td>Move the caret to allow typing directly after a widget</td><td>↓, →</td><td></td></tr><tr><td>After entering a nested editable, move the selection to the closest ancestor widget. For example: move from an image caption to the whole image widget.</td><td>Tab then Esc</td><td></td></tr></tbody></table></figure><p>Specifically for lists:</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Increase list item indent</td><td>⇥</td><td></td></tr><tr><td>Decrease list item indent</td><td>Shift+⇥</td><td>⇧⇥</td></tr></tbody></table></figure><p>In tables:</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Move the selection to the next cell</td><td>⇥</td><td></td></tr><tr><td>Move the selection to the previous cell</td><td>Shift+⇥</td><td>⇧⇥</td></tr><tr><td>Insert a new table row (when in the last cell of a table)</td><td>⇥</td><td></td></tr><tr><td>Navigate through the table</td><td>↑, →, ↓, ←</td><td></td></tr></tbody></table></figure><h3>General UI shortcuts</h3><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Close contextual balloons, dropdowns, and dialogs</td><td>Esc</td><td></td></tr><tr><td>Open the accessibility help dialog</td><td>Alt+0</td><td>⌥0</td></tr><tr><td>Move focus between form fields (inputs, buttons, etc.)</td><td>⇥, Shift+⇥</td><td>⇥, ⇧⇥</td></tr><tr><td>Move focus to the toolbar, navigate between toolbars</td><td>Alt+F10</td><td>⌥F10 (may require Fn)</td></tr><tr><td>Navigate through the toolbar or menu bar</td><td>↑, →, ↓, ←</td><td></td></tr><tr><td>Navigate to the next focusable field or an element outside the editor</td><td>Tab, Shift+Tab</td><td></td></tr><tr><td>Execute the currently focused button. Executing buttons that interact with the editor content moves the focus back to the content.</td><td>Enter, Space</td><td></td></tr><tr><td>Move focus in and out of an active dialog window</td><td>Ctrl+F6</td><td>⌘F6 (may require Fn)</td></tr></tbody></table></figure>",
"_help_UmgZAfcltxkS": "<p>Link previews turn a pasted URL into a rich, metadata-aware widget that can be displayed in three visual modes:</p><h2>Display modes</h2><p>A link preview can be displayed in one of three modes:</p><ul><li><strong>Inline</strong> — a link showing the site's favicon and page title (quite similar to&nbsp;<a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>). Use this when you want the link to flow with the surrounding paragraph.</li><li><strong>Card</strong> — a block-level preview with thumbnail, title, description, and site name. Use this when the link is the focus of a paragraph.</li><li><strong>Embed</strong> — a block-level interactive embed.<ul><li>Currently supported for YouTube videos, which render interactively (via an <code>iframe</code>).</li><li>To prevent unwanted remote requests, the video is shown only after clicking on it first. Until then, the video's thumbnail is shown with a play button.</li></ul></li></ul><div class=\"trilium-multicolumn-layout\" data-trilium-column-ratios=\"1-1-1\"><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:251/42;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Link%20Previews_image.png\" width=\"251\" height=\"42\"><figcaption><em>Inline</em> link preview</figcaption></figure></div><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:1217/196;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Link%20Previews_image.png\" width=\"1217\" height=\"196\"><figcaption><em>Card</em> link preview</figcaption></figure></div><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:994/563;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Link%20Previews_image.png\" width=\"994\" height=\"563\"><figcaption><em>Embed</em> link preview</figcaption></figure></div></div><h2>Inserting a link preview</h2><p>There are three ways to create one:</p><h3>1. By pasting a URL</h3><p>A link preview is automatically created:</p><ul><li>By pasting the URL and pressing <kbd>Space</kbd>. This will create an <em>inline</em> link preview.</li><li>When at the start of a new paragraph, pressing <kbd>Enter</kbd> will create a <em>card</em> or an <em>embed</em> for YouTube URLs.</li></ul><p>To undo an automatic link preview, press <kbd>Ctrl</kbd>+<kbd>Z</kbd> immediately afterwards which keeps it as a plain link instead. Alternatively, once a link preview was created, click on the link and select <em>Plain link</em> from the link preview toolbar.</p><p>This automatic conversion can be disabled by going to&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Text Notes</em> and unchecking <em>Autogenerate link previews</em> from the <em>Features</em> section.</p><p>If the link is not accessible to the Trilium server (or the network request fails for any other reason), it will not be converted to a link preview.</p><aside class=\"admonition note\"><p>A URL is only auto-converted when the pasted text <em>is</em> the URL. Links with a display name (e.g. <a href=\"https://triliumnotes.org\">Trilium Notes website</a>) are left as plain links.</p></aside><h3>2. By using the \"Link preview\" toolbar button or slash command</h3><p>Click <em>Link preview</em> (<span class=\"tn-icon cke cke-trilium-link-preview\"></span>) in the formatting toolbar to open the <em>Link preview</em> popup. Paste the URL and choose the type of preview.</p><p>Alternatively, use <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a> and look for <em>link preview</em> (it is also found by <em>embed</em>, <em>url</em> or <em>video</em>), which opens the same popup at the cursor.</p><h3>3. By saving browser tabs from the Web Clipper</h3><p>When the&nbsp;<a class=\"reference-link\" href=\"#root/_help_MtPxeAWVAzMg\">Web Clipper</a>&nbsp;saves the tabs of a window, each tab becomes an <em>inline</em> link preview showing the title and favicon the browser displays for it. Because this data comes from the browser, pages behind a login keep their real title, and the Trilium server does not contact the saved pages.</p><p>When <em>Autogenerate link previews</em> is turned off, the tabs are saved as a list of plain links instead.</p><h2>Altering an existing link preview</h2><p>Click on an inserted link preview to select it, and a small toolbar will appear with the following options:</p><ul><li>The normal link operations (opening in a new tab, copying the link, unlinking).</li><li>A button to edit the title of the link preview. This is especially useful if the title is hidden behind a login screen.</li><li>A way to switch between the link preview modes (Inline, Card or Embed) as well as to convert it to a normal link instead.<ul><li>The Embed option is only enabled when the URL points to a supported service (YouTube today).</li></ul></li></ul><h2>Where the preview data comes from</h2><p>When you insert a link preview, Trilium fetches metadata once and stores it with the note:</p><ul><li><strong>YouTube URLs</strong>: the title and channel name are fetched via YouTube's public oEmbed endpoint, and the video's thumbnail is downloaded at up to 1280×720.</li><li><strong>All other URLs</strong>: Trilium fetches the page and reads OpenGraph tags (<code>og:title</code>, <code>og:description</code>, <code>og:image</code>, <code>og:site_name</code>), falling back to the page's <code>&lt;title&gt;</code> and <code>&lt;meta name=\"description\"&gt;</code>. The site's favicon and the page's image are downloaded as well.</li></ul><p>The text is kept in the note's HTML. The images are kept as system&nbsp;<a class=\"reference-link\" href=\"#root/_help_0vhv7lsOLy82\">Attachments</a> of the note, listed under <em>Generated by Trilium</em>.</p><p>Because the data is stored in the note itself, link previews continue to render correctly when you reopen the note, share/publish it, or export to HTML — without any further network requests.</p><p>The metadata is captured <strong>at insertion time</strong> and is not automatically refreshed. If the linked page later changes its title or thumbnail, you'll need to re-insert the link to pick up the new values. To refresh a link, simply create it again.</p><p>A YouTube embed inserted before v0.107.0 keeps its smaller thumbnail, shown blurred, until the link is inserted again.</p><p>When accessing a&nbsp;<a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a>, the data is fetched from the remote URL by the server and not the client.</p><h2>Known limitations</h2><ul><li>The Embed display mode currently only supports YouTube. Other video and media platforms fall back to a Card preview.</li><li>Pages that block automated fetches may produce a minimal preview (hostname only).</li><li>Link previews require the Trilium server to reach the target URL, so they won't generate previews for pages on networks the server can't see.</li></ul>",
"_help_QEAPj01N5f7w": "<p>There are two types of links:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_3IDVtesTQ8ds\">External links</a>, for standard hyperlinks to websites or other resources.</li><li><a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>&nbsp;for links to other notes within Trilium.<ul><li>The list of notes that refer to a particular note is called&nbsp;<a class=\"reference-link\" href=\"#root/_help_wfGXLmm7x27z\">Backlinks</a>.</li></ul></li></ul><h2>Note map</h2><p>Trilium provides a visualization of incoming and outgoing links for a particular note. See <a href=\"#root/_help_BCkXAVs63Ttv\">note map</a> for details.</p>",
- "_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_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>, or press <kbd>Ctrl</kbd>+<kbd>K</kbd>:<ul><li>Since v0.107.0, the <em>Add link</em> dialog opens on <em>Web link</em>. Type or paste the address, and optionally a <em>Link title</em>; without one, the link shows its address.</li><li>Press <kbd>Enter</kbd> or <em>Add link</em> to confirm.</li></ul></li><li>A simpler way is to paste the raw link and press space to turn it automatically into a link.</li><li>The&nbsp;<span class=\"tn-icon cke cke-trilium\"></span> button and <kbd>Ctrl</kbd>+<kbd>L</kbd> of&nbsp;<a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a> open the same dialog on <em>Note</em>. Select <em>Web link</em> at the top of the dialog to create an external link from there.</li></ul><p>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.</p><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>Open the <em>Add link</em> dialog as above (via the formatting toolbar, or <kbd>Ctrl</kbd>+<kbd>K</kbd>). The selected text becomes the text of the link.</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. 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>K</kbd>, <kbd>Ctrl</kbd>+<kbd>L</kbd> or one of the link buttons. <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>, as described above, or <em>Create child note</em>. <em>Create child note</em> creates the note under the note being edited without asking for its type, inserts the link and opens the new note in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, which offers the note types to turn it into while it is still empty.</li></ol><p>To create an empty child note and link to it before naming it, use <em>New child note</em>, described in <a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a>.</p><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>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>",
diff --git a/docs/User Guide/User Guide/Note Types/Text/Links/External links.md b/docs/User Guide/User Guide/Note Types/Text/Links/External links.md
index c833403e07..d7686dceee 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Links/External links.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Links/External links.md
@@ -3,23 +3,24 @@ An external link is a standard web link targeting for example a website. For exa
To create a link without a custom text:
-* Press <span class="tn-icon cke cke-link"></span> in the <a class="reference-link" href="../Formatting%20toolbar.md">Formatting toolbar</a>:
- * A popup will appear, type or paste the URL in the box.
- * Press <kbd>Enter</kbd> or the check mark icon to confirm.
-* Alternatively, press <kbd>Ctrl</kbd>+<kbd>K</kbd> to trigger the aforementioned popup.
+* Press <span class="tn-icon cke cke-link"></span> in the <a class="reference-link" href="../Formatting%20toolbar.md">Formatting toolbar</a>, or press <kbd>Ctrl</kbd>+<kbd>K</kbd>:
+ * Since v0.107.0, the _Add link_ dialog opens on _Web link_. Type or paste the address, and optionally a _Link title_; without one, the link shows its address.
+ * Press <kbd>Enter</kbd> or _Add link_ to confirm.
* A simpler way is to paste the raw link and press space to turn it automatically into a link.
-* Since v0.107.0, the _Add link_ dialog of <a class="reference-link" href="Internal%20(reference)%20links.md">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 _Web link_ at the top of the dialog, type or paste the address, and optionally a _Link title_; without one, the link shows its address. An address without a scheme, such as `example.com`, gets `https://`. A URL pasted into the _Note_ field, or picked from its search, switches the dialog to _Web link_. The dialog also opens on _Web link_ when the selected text is a URL.
+* The <span class="tn-icon cke cke-trilium"></span> button and <kbd>Ctrl</kbd>+<kbd>L</kbd> of <a class="reference-link" href="Internal%20(reference)%20links.md">Internal (reference) links</a> open the same dialog on _Note_. Select _Web link_ at the top of the dialog to create an external link from there.
+
+An address without a scheme, such as `example.com`, gets `https://`. A URL pasted into the _Note_ field, or picked from its search, switches the dialog to _Web link_. The dialog also opens on _Web link_ when the selected text is a URL.
To create a link with a custom text:
* First, type and select the text which will be turned into a link.
-* Follow the previous steps to open the link interface (via the formatting toolbar, or <kbd>Ctrl</kbd>+<kbd>K</kbd>).
+* Open the _Add link_ dialog as above (via the formatting toolbar, or <kbd>Ctrl</kbd>+<kbd>K</kbd>). The selected text becomes the text of the link.
* Alternatively, simply paste (<kbd>Ctrl</kbd>+<kbd>V</kbd>) over the selected text to turn it into a link.
Once a link is inserted:
* The text inside the link can be changed if needed but the link itself will remain.
-* To modify the link, click on the link to display the popup and press the <span class="tn-icon cke cke-pencil"></span> _Edit link_ button. Since v0.107.0, it opens the _Edit link_ 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. _Save link_ changes the whole link, its text included, and the dialog can also turn it into a link to a note.
+* To modify the link, click on the link to display the popup and press the <span class="tn-icon cke cke-pencil"></span> _Edit link_ button. It opens the _Edit link_ dialog, filled with the link's address and text, as do placing the cursor inside the link and pressing <kbd>Ctrl</kbd>+<kbd>K</kbd>, <kbd>Ctrl</kbd>+<kbd>L</kbd> or one of the link buttons. _Save link_ changes the whole link, its text included, and the dialog can also turn it into a link to a note.
* To remove a link, click on it and press the <span class="tn-icon cke cke-unlink"></span> _Unlink_ button.
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".
\ No newline at end of file
diff --git a/packages/ckeditor5/src/plugins/internallink.spec.ts b/packages/ckeditor5/src/plugins/internallink.spec.ts
index 228ee2ea09..310d93cd4a 100644
--- a/packages/ckeditor5/src/plugins/internallink.spec.ts
+++ b/packages/ckeditor5/src/plugins/internallink.spec.ts
@@ -1,6 +1,7 @@
import {
_getModelData as getModelData, _setModelData as setModelData, Bold, ButtonView, ClassicEditor, CodeBlock,
- ContextualBalloon, Essentials, Link, LinkEditing, LinkUI, Paragraph
+ ContextualBalloon, Essentials, keyCodes, type KeystrokeHandler, Link, LinkEditing, LinkUI,
+ Paragraph
} from "ckeditor5";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -193,3 +194,94 @@ describe("the edit button of the link toolbar", () => {
expect(linkUI.formView && balloon.hasView(linkUI.formView)).toBe(false);
});
});
+
+describe("the link button and Ctrl+K", () => {
+ let editor: ClassicEditor;
+ let openDialog: ReturnType<typeof vi.fn>;
+
+ beforeEach(async () => {
+ openDialog = vi.fn();
+ editor = await createTestEditor([Essentials, Paragraph, Link, InternalLinkPlugin], {
+ internalLink: { openDialog }
+ });
+ });
+
+ const IN_LINK = "<paragraph><$text linkHref=\"https://a.example\">fo[]o</$text></paragraph>";
+
+ /** Presses Ctrl+K on `keystrokes`, reporting whether a handler took the key. */
+ function pressCtrlK(keystrokes: KeystrokeHandler) {
+ const preventDefault = vi.fn();
+ keystrokes.press({
+ keyCode: keyCodes.k, ctrlKey: true, shiftKey: false, altKey: false, metaKey: false,
+ preventDefault, stopPropagation: vi.fn()
+ } as unknown as KeyboardEvent);
+ return preventDefault.mock.calls.length > 0;
+ }
+
+ function isLinkFormShown() {
+ const formView = editor.plugins.get(LinkUI).formView;
+ return !!formView && editor.plugins.get(ContextualBalloon).hasView(formView);
+ }
+
+ it("opens the link dialog on the web link side from the Link button", () => {
+ setModelData(editor.model, "<paragraph>foo[]</paragraph>");
+ const button = editor.ui.componentFactory.create("link") as ButtonView;
+ expect(button.label).toBe("Link");
+ expect(button.keystroke).toBe("Ctrl+K");
+ expect(button.isOn).toBe(false);
+
+ button.fire("execute");
+ expect(openDialog).toHaveBeenCalledExactlyOnceWith({ target: "url" });
+ expect(isLinkFormShown()).toBe(false);
+
+ // The button shows as on in a link, and off where no link can be made.
+ setModelData(editor.model, IN_LINK);
+ expect(button.isOn).toBe(true);
+ editor.enableReadOnlyMode("test");
+ expect(button.isEnabled).toBe(false);
+ });
+
+ it("opens the link dialog on Ctrl+K in the text", () => {
+ setModelData(editor.model, "<paragraph>foo[]</paragraph>");
+ expect(pressCtrlK(editor.keystrokes)).toBe(true);
+ expect(openDialog).toHaveBeenCalledExactlyOnceWith({ target: "url" });
+ expect(isLinkFormShown()).toBe(false);
+ });
+
+ it("opens the link dialog once on Ctrl+K in the link toolbar, each time it shows", () => {
+ setModelData(editor.model, IN_LINK);
+ const linkUI = editor.plugins.get(LinkUI);
+ const balloon = editor.plugins.get(ContextualBalloon);
+ const add = vi.spyOn(balloon, "add");
+ const showToolbar = () => (linkUI as unknown as { _showUI(): void })._showUI();
+
+ for (let shown = 1; shown <= 2; shown++) {
+ showToolbar();
+ const element = linkUI.toolbarView?.element;
+ expect(element && balloon.hasView(linkUI.toolbarView)).toBe(true);
+ if (!element) return;
+
+ // A DOM event, which both the toolbar and `editor.keystrokes` listen for.
+ const keydown = new KeyboardEvent("keydown", {
+ keyCode: keyCodes.k, ctrlKey: true, bubbles: true, cancelable: true
+ });
+ element.dispatchEvent(keydown);
+ expect(keydown.defaultPrevented).toBe(true);
+ expect(openDialog).toHaveBeenCalledTimes(shown);
+ expect(balloon.hasView(linkUI.toolbarView)).toBe(false);
+ }
+ expect(linkUI.formView).not.toBeNull();
+ expect(add.mock.calls.map(([ { view } ]) => view)).not.toContain(linkUI.formView);
+ });
+
+ it("keeps the link form of CKEditor in an editor without the link dialog", async () => {
+ const plainEditor = await createTestEditor([
+ Essentials, Paragraph, Link, InternalLinkPlugin
+ ]);
+ setModelData(plainEditor.model, "<paragraph>foo[]</paragraph>");
+ plainEditor.ui.componentFactory.create("link").fire("execute");
+
+ const formView = plainEditor.plugins.get(LinkUI).formView;
+ expect(formView && plainEditor.plugins.get(ContextualBalloon).hasView(formView)).toBe(true);
+ });
+});
diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.ts
index 03110bab6e..eb173903b0 100644
--- a/packages/ckeditor5/src/plugins/internallink.ts
+++ b/packages/ckeditor5/src/plugins/internallink.ts
@@ -1,12 +1,21 @@
import {
- ButtonView, Command, findAttributeRange, IconPencil, LinkUI, ModelLiveRange, Plugin
+ ButtonView, Command, ContextualBalloon, findAttributeRange, IconLink, IconPencil, LinkUI,
+ ModelLiveRange, Plugin
} from 'ckeditor5';
-import type { Editor, ModelRange } from 'ckeditor5';
+import type { Editor, LinkCommand, ModelRange, View } from 'ckeditor5';
import internalLinkIcon from '../icons/trilium.svg?raw';
import ReferenceLink, { getReferenceTitle, referenceAttributes } from './referencelink';
export const COMMAND_NAME = 'insertInternalLink';
+/** The keystroke of `LinkUI`, which opens its link form. */
+const LINK_KEYSTROKE = 'Ctrl+K';
+
+export interface InternalLinkDialogOptions {
+ /** The side the dialog opens on for a new link: a note, or a web address. */
+ target?: 'note' | 'url';
+}
+
export default class InternalLinkPlugin extends Plugin {
static get requires() {
@@ -43,17 +52,42 @@ export default class InternalLinkPlugin extends Plugin {
});
}
- /** Replaces the `editLink` button of `LinkUI`, which opens the link form in the balloon. */
+ /**
+ * Opens the link dialog from every place `LinkUI` opens its link form: the `link` and
+ * `editLink` buttons, Ctrl+K in the text and Ctrl+K in the link toolbar. A new link opens on
+ * the web link side.
+ */
afterInit() {
const editor = this.editor;
const t = editor.t;
const command = editor.commands.get(COMMAND_NAME);
- if (!editor.plugins.has(LinkUI) || !command) {
+ if (!editor.plugins.has(LinkUI) || !command || !editor.config.get('internalLink')) {
return;
}
- // `_hideUI()` is private, and the only way to close the toolbar together with its listeners.
- const linkUI = editor.plugins.get(LinkUI) as unknown as { _hideUI(updateFocus?: boolean): void };
+ const linkUI = editor.plugins.get(LinkUI);
+ const openLinkDialog = () => {
+ // `_hideUI()` is private, and the only way to close the toolbar with its listeners.
+ (linkUI as unknown as { _hideUI(updateFocus?: boolean): void })._hideUI(false);
+ editor.execute(COMMAND_NAME, { target: 'url' });
+ };
+
+ editor.ui.componentFactory.add('link', locale => {
+ const linkCommand = editor.commands.get('link') as LinkCommand;
+ const button = new ButtonView(locale);
+ button.set({
+ label: t('Link'),
+ icon: IconLink,
+ keystroke: LINK_KEYSTROKE,
+ isToggleable: true,
+ tooltip: true
+ });
+ button.bind('isEnabled').to(command, 'isEnabled');
+ button.bind('isOn').to(linkCommand, 'value', value => !!value);
+ this.listenTo(button, 'execute', openLinkDialog);
+ return button;
+ });
+
editor.ui.componentFactory.add('editLink', locale => {
const button = new ButtonView(locale);
button.set({
@@ -62,12 +96,30 @@ export default class InternalLinkPlugin extends Plugin {
tooltip: true
});
button.bind('isEnabled').to(command, 'isEnabled');
- this.listenTo(button, 'execute', () => {
- linkUI._hideUI(false);
- editor.execute(COMMAND_NAME);
- });
+ this.listenTo(button, 'execute', openLinkDialog);
return button;
});
+
+ // Ahead of the keystroke of `LinkUI`, which opens the link form.
+ editor.keystrokes.set(LINK_KEYSTROKE, (_data, cancel) => {
+ cancel();
+ openLinkDialog();
+ }, { priority: 'high' });
+
+ // `LinkUI` creates its toolbar the first time it shows, with a Ctrl+K that opens the link
+ // form. `editor.keystrokes` also listens on the toolbar, and opens the dialog.
+ let isToolbarKeystrokeSet = false;
+ const balloon = editor.plugins.get(ContextualBalloon);
+ this.listenTo(balloon, 'change:visibleView', (_evt, _name, view: View | null) => {
+ const toolbarView = linkUI.toolbarView;
+ if (isToolbarKeystrokeSet || !toolbarView || view !== toolbarView) {
+ return;
+ }
+ toolbarView.keystrokes.set(LINK_KEYSTROKE, (_data, cancel) => cancel(), {
+ priority: 'high'
+ });
+ isToolbarKeystrokeSet = true;
+ });
}
}
@@ -81,8 +133,8 @@ class InsertInternalLinkCommand extends Command {
this.isEnabled = !this.editor.isReadOnly && !isInCodeBlock;
}
- execute() {
- this.editor.config.get('internalLink')?.openDialog();
+ execute(options?: InternalLinkDialogOptions) {
+ this.editor.config.get('internalLink')?.openDialog(options);
}
}
@@ -171,8 +223,8 @@ function findLinkAtSelection(editor: Editor): { href: string; range: ModelRange
declare module 'ckeditor5' {
interface EditorConfig {
internalLink?: {
- /** Opens the dialog that adds a link to a note at the selection, or edits the link there. */
- openDialog(): void;
+ /** Opens the dialog that adds a link at the selection, or edits the link there. */
+ openDialog(options?: InternalLinkDialogOptions): void;
};
}
}