Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/link editor: refactor

Adorian Doran6635366dae48
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 852ff9ba71..b0cb389b5b 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -18,10 +18,10 @@ import toast from "../services/toast.js";
import utils, { reuseAcrossHotReloads } from "../services/utils.js";
import { ReactWrappedWidget } from "../widgets/basic_widget.js";
import type RootContainer from "../widgets/containers/root_container.js";
-import { AddLinkOpts } from "../widgets/dialogs/add_link.jsx";
import type { ConfirmWithMessageOptions, ConfirmWithTitleOptions } from "../widgets/dialogs/confirm.js";
import { ContentEmbedOpts } from "../widgets/dialogs/content_embed.jsx";
import type { ResolveOptions } from "../widgets/dialogs/delete_notes.js";
+import { EditLinkOpts } from "../widgets/dialogs/edit_link.jsx";
import { IconPickerOpts } from "../widgets/dialogs/icon_picker.jsx";
import type { InfoProps } from "../widgets/dialogs/info.jsx";
import type { ResourceDownloadDialogOptions } from "../widgets/dialogs/resource_download.jsx";
@@ -281,7 +281,7 @@ export type CommandMappings = {
showProtectedSessionPasswordDialog: CommandData;
showUploadAttachmentsDialog: CommandData & { noteId: string };
showContentEmbedDialog: CommandData & ContentEmbedOpts;
- showAddLinkDialog: CommandData & AddLinkOpts;
+ showEditLinkDialog: CommandData & EditLinkOpts;
showIconPickerDialog: CommandData & IconPickerOpts;
showPasteMarkdownDialog: CommandData & MarkdownImportOpts;
closeProtectedSessionPasswordDialog: CommandData;
@@ -596,7 +596,7 @@ type EventMappings = {
noteTypeMimeChanged: { noteId: string };
zenModeChanged: { isEnabled: boolean };
activeNoteChanged: {ntxId: string | null | undefined};
- showAddLinkDialog: AddLinkOpts;
+ showEditLinkDialog: EditLinkOpts;
showContentEmbedDialog: ContentEmbedOpts;
openBulkActionsDialog: {
selectedOrActiveNoteIds: string[];
diff --git a/apps/client/src/layouts/layout_commons.tsx b/apps/client/src/layouts/layout_commons.tsx
index b4b802cedc..77843aa1e6 100644
--- a/apps/client/src/layouts/layout_commons.tsx
+++ b/apps/client/src/layouts/layout_commons.tsx
@@ -23,7 +23,7 @@ export function applyModals(rootContainer: RootContainer) {
.child(<LazyDialog triggerEvents={["showNotePickerDialog"]} loader={() => import("../widgets/dialogs/note_picker.js")} />)
.child(<LazyDialog triggerEvents={["chooseNoteType"]} loader={() => import("../widgets/dialogs/note_type_chooser.js")} />)
.child(<LazyDialog triggerEvents={["jumpToNote", "commandPalette"]} loader={() => import("../widgets/dialogs/jump_to_note.js")} />)
- .child(<LazyDialog triggerEvents={["showAddLinkDialog"]} loader={() => import("../widgets/dialogs/add_link.js")} />)
+ .child(<LazyDialog triggerEvents={["showEditLinkDialog"]} loader={() => import("../widgets/dialogs/edit_link.js")} />)
.child(<LazyDialog triggerEvents={["showIconPickerDialog"]} loader={() => import("../widgets/dialogs/icon_picker.js")} />)
.child(<LazyDialog triggerEvents={["cloneNoteIdsTo"]} loader={() => import("../widgets/dialogs/clone_to.js")} />)
.child(<LazyDialog triggerEvents={["moveBranchIdsTo"]} loader={() => import("../widgets/dialogs/move_to.js")} />)
diff --git a/apps/client/src/widgets/dialogs/add_link.css b/apps/client/src/widgets/dialogs/edit_link.css
similarity index 72%
rename from apps/client/src/widgets/dialogs/add_link.css
rename to apps/client/src/widgets/dialogs/edit_link.css
index 4d51923753..9e2387061a 100644
--- a/apps/client/src/widgets/dialogs/add_link.css
+++ b/apps/client/src/widgets/dialogs/edit_link.css
@@ -1,4 +1,4 @@
-.add-link-balloon {
+.edit-link-balloon {
padding: 8px;
/* Keeps the card wider than the 500px at which Card.css stacks its rows. */
width: 34rem;
@@ -9,13 +9,13 @@
white-space: normal;
text-align: start;
- .add-link-actions {
+ .edit-link-actions {
display: flex;
justify-content: flex-end;
}
}
-:is(.modal.add-link-dialog, .add-link-balloon) {
+:is(.modal.edit-link-dialog, .edit-link-balloon) {
.tn-card {
margin-bottom: 1rem;
}
@@ -26,11 +26,11 @@
/* Matches the 500px at which Card.css stacks a wide control under its label. */
@container (min-width: 501px) {
- :is(.add-link-note, .add-link-url, .add-link-text) {
- --add-link-label-width: 8em;
+ :is(.edit-link-note, .edit-link-url, .edit-link-text) {
+ --edit-link-label-width: 8em;
> .tn-card-option-label {
- flex: 0 0 var(--add-link-label-width);
+ flex: 0 0 var(--edit-link-label-width);
min-width: max-content;
}
@@ -40,18 +40,18 @@
}
}
- .add-link-text.tn-card-section-nested {
- --add-link-label-width: calc(8em - var(--card-nested-section-indent));
+ .edit-link-text.tn-card-section-nested {
+ --edit-link-label-width: calc(8em - var(--card-nested-section-indent));
}
}
- .add-link-target {
+ .edit-link-target {
display: flex;
width: fit-content;
margin: 0 auto 1rem;
}
- .add-link-anchors .tn-card-body {
+ .edit-link-anchors .tn-card-body {
border-radius: var(--card-border-radius);
height: 150px;
overflow-y: auto;
@@ -64,7 +64,7 @@
outline-offset: -2px;
}
- > .add-link-no-anchors {
+ > .edit-link-no-anchors {
flex-grow: 1;
}
}
diff --git a/apps/client/src/widgets/dialogs/add_link.spec.tsx b/apps/client/src/widgets/dialogs/edit_link.spec.tsx
similarity index 93%
rename from apps/client/src/widgets/dialogs/add_link.spec.tsx
rename to apps/client/src/widgets/dialogs/edit_link.spec.tsx
index a5f9044776..e68955de66 100644
--- a/apps/client/src/widgets/dialogs/add_link.spec.tsx
+++ b/apps/client/src/widgets/dialogs/edit_link.spec.tsx
@@ -8,9 +8,9 @@ import { buildNote } from "../../test/easy-froca";
import { renderInto } from "../../test/render";
import Modal from "../react/Modal";
import { ParentComponent } from "../react/react_utils";
-import AddLinkDialog, {
- AddLinkBalloon, type AddLinkOpts, getShownDisplay, normalizeWebLink
-} from "./add_link";
+import EditLinkDialog, {
+ EditLinkBalloon, type EditLinkOpts, getShownDisplay, normalizeWebLink
+} from "./edit_link";
const autocomplete = vi.hoisted(() => ({
onChange: undefined as ((suggestion: Suggestion | null) => void) | undefined
@@ -53,11 +53,11 @@ describe("getShownDisplay", () => {
});
});
-describe("AddLinkDialog", () => {
+describe("EditLinkDialog", () => {
let host: Component;
let container: HTMLElement;
- const addLink = vi.fn<AddLinkOpts["addLink"]>(async () => {});
- const addLinkPreview = vi.fn<NonNullable<AddLinkOpts["addLinkPreview"]>>(async () => {});
+ const addLink = vi.fn<EditLinkOpts["addLink"]>(async () => {});
+ const addLinkPreview = vi.fn<NonNullable<EditLinkOpts["addLinkPreview"]>>(async () => {});
beforeEach(() => {
vi.clearAllMocks();
@@ -65,14 +65,14 @@ describe("AddLinkDialog", () => {
host = new Component();
container = renderInto(
<ParentComponent.Provider value={host}>
- <AddLinkDialog />
+ <EditLinkDialog />
</ParentComponent.Provider>
);
});
- async function open(opts: Partial<AddLinkOpts> = {}) {
+ async function open(opts: Partial<EditLinkOpts> = {}) {
await act(async () => {
- void host.handleEventInChildren("showAddLinkDialog", {
+ void host.handleEventInChildren("showEditLinkDialog", {
text: "", hasSelection: false, addLink, ...opts
});
});
@@ -91,12 +91,12 @@ describe("AddLinkDialog", () => {
}
function mirrorToggle() {
- return container.querySelector<HTMLInputElement>(".add-link-mirror input.switch-toggle");
+ return container.querySelector<HTMLInputElement>(".edit-link-mirror input.switch-toggle");
}
/** Whether the row of the field is indented under the row it depends on. */
function nested(name: "url" | "text") {
- return container.querySelector(`.add-link-${name}`)?.classList.contains("tn-card-section-nested");
+ return container.querySelector(`.edit-link-${name}`)?.classList.contains("tn-card-section-nested");
}
/** The rows that put their control under the label rather than beside it. */
@@ -105,15 +105,15 @@ describe("AddLinkDialog", () => {
}
function field(name: "url" | "text") {
- return container.querySelector<HTMLInputElement>(`.add-link-${name} input`);
+ return container.querySelector<HTMLInputElement>(`.edit-link-${name} input`);
}
function displaySelect() {
- return container.querySelector<HTMLSelectElement>(".add-link-display select");
+ return container.querySelector<HTMLSelectElement>(".edit-link-display select");
}
function anchorRows() {
- return [ ...container.querySelectorAll<HTMLElement>(".add-link-anchors .tn-card-choice") ];
+ return [ ...container.querySelectorAll<HTMLElement>(".edit-link-anchors .tn-card-choice") ];
}
function checkedAnchor() {
@@ -171,7 +171,7 @@ describe("AddLinkDialog", () => {
await act(async () => choice()[0]?.click());
await type(field("url"), "https://trilium.cc");
expect(nested("text")).toBe(false);
- expect(container.querySelector(".add-link-url + .add-link-text")).not.toBeNull();
+ expect(container.querySelector(".edit-link-url + .edit-link-text")).not.toBeNull();
expect(stacked()).toStrictEqual([]);
await type(field("text"), "Trilium");
await submit();
@@ -294,7 +294,7 @@ describe("AddLinkDialog", () => {
host = new Component();
container = renderInto(
<ParentComponent.Provider value={host}>
- <AddLinkDialog />
+ <EditLinkDialog />
</ParentComponent.Provider>
);
const mobilePicker = await openAndShow();
@@ -426,7 +426,7 @@ describe("AddLinkDialog", () => {
expect(container.querySelector(".note-autocomplete")).toBeNull();
expect(headings()).toStrictEqual([ "add_link.target_anchor" ]);
const titleCard = field("text")?.closest(".tn-card");
- expect(titleCard?.nextElementSibling?.classList.contains("add-link-anchors")).toBe(true);
+ expect(titleCard?.nextElementSibling?.classList.contains("edit-link-anchors")).toBe(true);
expect(anchorRows().map((row) => row.textContent)).toStrictEqual([ "intro", "outro" ]);
expect(anchorRows().every((row) => row.querySelector(".tn-card-choice-icon.bx-bookmark")))
.toBe(true);
@@ -473,24 +473,24 @@ describe("AddLinkDialog", () => {
await open({ anchors: [] });
await act(async () => choice()[2]?.click());
expect(anchorRows()).toStrictEqual([]);
- expect(container.querySelector(".add-link-anchors .no-items")?.textContent)
+ expect(container.querySelector(".edit-link-anchors .no-items")?.textContent)
.toBe("add_link.no_anchors");
});
});
-describe("AddLinkBalloon", () => {
- const addLink = vi.fn<AddLinkOpts["addLink"]>(async () => {});
+describe("EditLinkBalloon", () => {
+ const addLink = vi.fn<EditLinkOpts["addLink"]>(async () => {});
const onClose = vi.fn();
beforeEach(() => {
vi.clearAllMocks();
});
- async function show(opts: Partial<AddLinkOpts> = {}) {
+ async function show(opts: Partial<EditLinkOpts> = {}) {
const rendered: { container?: HTMLElement } = {};
await act(async () => {
rendered.container = renderInto(
- <AddLinkBalloon
+ <EditLinkBalloon
opts={{ text: "", hasSelection: false, addLink, ...opts }}
onClose={onClose}
/>
@@ -512,7 +512,7 @@ describe("AddLinkBalloon", () => {
expect(document.activeElement).toBe(noteForm.querySelector(".note-autocomplete"));
const form = await show({ target: "url" });
- const url = form.querySelector<HTMLInputElement>(".add-link-url input");
+ const url = form.querySelector<HTMLInputElement>(".edit-link-url input");
expect(url).not.toBeNull();
expect(document.activeElement).toBe(url);
@@ -533,14 +533,14 @@ describe("AddLinkBalloon", () => {
await vi.waitFor(() => expect(document.querySelector(".host-modal.show")).not.toBeNull());
const form = await show({ target: "url" });
- expect(document.activeElement).toBe(form.querySelector(".add-link-url input"));
+ expect(document.activeElement).toBe(form.querySelector(".edit-link-url input"));
});
it("opens on an edited link with its address selected, and applies it left alone", async () => {
const form = await show({
currentLink: { externalLink: "https://example.com/page" }, currentTitle: "Page"
});
- const url = form.querySelector<HTMLInputElement>(".add-link-url input");
+ const url = form.querySelector<HTMLInputElement>(".edit-link-url input");
expect(url?.value).toBe("https://example.com/page");
expect([ url?.selectionStart, url?.selectionEnd ]).toStrictEqual([ 0, url?.value.length ]);
@@ -553,7 +553,7 @@ describe("AddLinkBalloon", () => {
const edited = await show({
anchors: [ "intro" ], currentAnchor: "intro", currentTitle: "Intro"
});
- const title = edited.querySelector<HTMLInputElement>(".add-link-text input");
+ const title = edited.querySelector<HTMLInputElement>(".edit-link-text input");
expect(document.activeElement).toBe(title);
expect([ title?.selectionStart, title?.selectionEnd ]).toStrictEqual([ 0, 5 ]);
await submit(edited);
@@ -563,11 +563,11 @@ describe("AddLinkBalloon", () => {
const form = await show({ anchors: [ "intro" ] });
const buttons = form.querySelectorAll<HTMLButtonElement>(".tn-segmented-choice button");
await act(async () => buttons[2]?.click());
- expect(document.activeElement).toBe(form.querySelector(".add-link-text input"));
+ expect(document.activeElement).toBe(form.querySelector(".edit-link-text input"));
await submit(form);
expect(onClose).toHaveBeenCalledOnce();
- const row = form.querySelector<HTMLElement>(".add-link-anchors .tn-card-choice");
+ const row = form.querySelector<HTMLElement>(".edit-link-anchors .tn-card-choice");
await act(async () => row?.click());
await submit(form);
expect(onClose).toHaveBeenCalledTimes(2);
diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/edit_link.tsx
similarity index 95%
rename from apps/client/src/widgets/dialogs/add_link.tsx
rename to apps/client/src/widgets/dialogs/edit_link.tsx
index 2f0ac3465d..764fe5adfb 100644
--- a/apps/client/src/widgets/dialogs/add_link.tsx
+++ b/apps/client/src/widgets/dialogs/edit_link.tsx
@@ -1,4 +1,4 @@
-import "./add_link.css";
+import "./edit_link.css";
import type { LinkDisplayMode } from "@triliumnext/ckeditor5";
import internalLinkIcon from "@triliumnext/ckeditor5/src/icons/trilium.svg?raw";
@@ -49,7 +49,7 @@ function findAnchorIds(content: string): string[] {
return ids;
}
-export interface AddLinkOpts {
+export interface EditLinkOpts {
text: string;
hasSelection: boolean;
/**
@@ -108,20 +108,20 @@ export interface AddLinkOpts {
addLinkPreview?(url: string, display: LinkDisplayMode, title: string | null): Promise<void>;
}
-export default function AddLinkDialog() {
- const [ opts, setOpts ] = useState<AddLinkOpts>();
+export default function EditLinkDialog() {
+ const [ opts, setOpts ] = useState<EditLinkOpts>();
const [ shown, setShown ] = useState(false);
const hasSubmittedRef = useRef(false);
- const form = useAddLinkForm(opts);
+ const form = useEditLinkForm(opts);
- useTriliumEvent("showAddLinkDialog", opts => {
+ useTriliumEvent("showEditLinkDialog", opts => {
setOpts(opts);
setShown(true);
});
function onSubmit() {
if (!form.hasLink) {
- logError("No link to add.");
+ logError("No link to apply.");
return;
}
@@ -132,7 +132,7 @@ export default function AddLinkDialog() {
return (
<Modal
- className="add-link-dialog"
+ className="edit-link-dialog"
size="lg"
title={form.title}
helpPageId="QEAPj01N5f7w"
@@ -159,11 +159,11 @@ export default function AddLinkDialog() {
* The form of the link dialog in the balloon that the text editor places at the caret. `onClose`
* closes the balloon.
*/
-export function AddLinkBalloon({ opts, onClose }: { opts: AddLinkOpts; onClose(): void }) {
+export function EditLinkBalloon({ opts, onClose }: { opts: EditLinkOpts; onClose(): void }) {
// Lets the fields take focus inside a modal, such as the quick edit popup. Runs before the
- // effects of `useAddLinkForm()`, which focus the fields.
+ // effects of `useEditLinkForm()`, which focus the fields.
useEffect(() => suspendModalFocusTraps(), []);
- const form = useAddLinkForm(opts);
+ const form = useEditLinkForm(opts);
useEffect(() => {
form.onShown();
@@ -180,7 +180,7 @@ export function AddLinkBalloon({ opts, onClose }: { opts: AddLinkOpts; onClose()
}}
>
{form.body}
- <div className="add-link-actions">
+ <div className="edit-link-actions">
<Button text={form.buttonText} keyboardShortcut="Enter" />
</div>
</form>
@@ -188,7 +188,7 @@ export function AddLinkBalloon({ opts, onClose }: { opts: AddLinkOpts; onClose()
}
/** The state and the fields of the link dialog for `opts`, shared by the modal and the balloon. */
-function useAddLinkForm(opts: AddLinkOpts | undefined) {
+function useEditLinkForm(opts: EditLinkOpts | undefined) {
const [ linkTitle, setLinkTitle ] = useState("");
const [ linkType, setLinkType ] = useState<LinkType>();
const [ suggestion, setSuggestion ] = useState<Suggestion | null>(null);
@@ -461,7 +461,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
const titleSection = (
<OptionCardSection
- className="add-link-text" name="link-title" label={t("add_link.link_title")}
+ className="edit-link-text" name="link-title" label={t("add_link.link_title")}
>
<FormTextBox
inputRef={titleRef}
@@ -481,7 +481,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
}
const switcher = !opts?.fixLink && (
<SegmentedChoice<LinkTarget>
- className="add-link-target"
+ className="edit-link-target"
options={targets}
currentValue={target}
onChange={(next) => changeTarget(next)}
@@ -492,7 +492,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
const anchorPage = (<>
{showsTitle && <Card>{titleSection}</Card>}
- <Card className="add-link-anchors" heading={t("add_link.target_anchor")}>
+ <Card className="edit-link-anchors" heading={t("add_link.target_anchor")}>
{anchors.length > 0 ? anchors.map((name) => (
<ChoiceCardSection
key={name}
@@ -503,7 +503,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
{name}
</ChoiceCardSection>
)) : (
- <CardSection className="add-link-no-anchors">
+ <CardSection className="edit-link-no-anchors">
<NoItems icon="bx bx-bookmark" text={t("add_link.no_anchors")} size="small" />
</CardSection>
)}
@@ -536,7 +536,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
{target === "url" ? (
<>
<OptionCardSection
- className="add-link-url" name="url" label={t("add_link.url")}
+ className="edit-link-url" name="url" label={t("add_link.url")}
>
<FormTextBox
inputRef={webLinkRef}
@@ -554,7 +554,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
{showsDisplay && (
<OptionCardSection
- className="add-link-display" name="display"
+ className="edit-link-display" name="display"
label={t("add_link.display_as")}
>
<FormSelect
@@ -571,7 +571,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
) : (
<>
<OptionCardSection
- className="add-link-note" name="note" label={t("add_link.note")}
+ className="edit-link-note" name="note" label={t("add_link.note")}
>
<NoteAutocomplete
inputRef={autocompleteRef}
@@ -617,7 +617,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
{showsTitle && (
<OptionCardSection
- className="add-link-mirror"
+ className="edit-link-mirror"
name="mirror-title"
label={t("add_link.mirror_title")}
description={t("add_link.mirror_title_description")}
@@ -644,7 +644,7 @@ function useAddLinkForm(opts: AddLinkOpts | undefined) {
* `initialWebLink`, and Note otherwise.
*/
function getInitialTarget(
- opts: AddLinkOpts | undefined, initialWebLink: string | null
+ opts: EditLinkOpts | undefined, initialWebLink: string | null
): LinkTarget {
if (opts?.currentAnchor) return "anchor";
return initialWebLink !== null ? "url" : "note";
@@ -655,7 +655,7 @@ function getInitialTarget(
* 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 {
+function getInitialWebLink(opts: EditLinkOpts): string | null {
if (opts.fixLink) return null;
if (opts.currentLink) return opts.currentLink.externalLink ?? null;
const text = opts.text.trim();
diff --git a/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx b/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx
index 9d8a45d7e0..4fe1116a29 100644
--- a/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx
+++ b/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx
@@ -25,7 +25,7 @@ import SplitEditor from "../helpers/SplitEditor";
import { ReadOnlyTextContent } from "../text/ReadOnlyText";
import { TypeWidgetProps } from "../type_widget";
import {
- insertDateTime, insertText, replaceSelection, showAddLinkDialog, showIncludeNoteDialog,
+ insertDateTime, insertText, replaceSelection, showEditLinkDialog, showIncludeNoteDialog,
uploadImageAndInsert
} from "./editor_utils";
@@ -85,7 +85,7 @@ export default function Markdown(props: TypeWidgetProps) {
const [ previewEl, setPreviewEl ] = useState<HTMLDivElement | null>(null);
const { html, headings, highlights } = useMemo(() => renderWithSourceLines(content), [ content ]);
- // Bind text-detail shortcuts (e.g. Ctrl+L for add link) to CodeMirror's contentDOM,
+ // Bind text-detail shortcuts (e.g. Ctrl+L for the edit link dialog) to CodeMirror's contentDOM,
// since the outer `dom` only receives events after CodeMirror has already handled them.
useEffect(() => {
if (!editorView || !props.parentComponent) return;
@@ -366,13 +366,13 @@ export function findActiveBlock(blocks: ArrayLike<HTMLElement>, activeLine: numb
//#region Text commands
/**
* Handles text-detail commands for the Markdown editor:
- * - Add Link (Ctrl+L): opens the add-link dialog, inserts markdown link syntax
+ * - Add Link (Ctrl+L): opens the edit link dialog, inserts markdown link syntax
* - Insert Date/Time (Alt+T): inserts a formatted date/time string
*/
function useTextCommands(editorView: VanillaCodeMirror | null) {
useLegacyImperativeHandlers({
addLinkToTextCommand() {
- if (editorView) showAddLinkDialog(editorView);
+ if (editorView) showEditLinkDialog(editorView);
},
insertDateTimeToTextCommand() {
diff --git a/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts b/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts
index e601607816..d867bd16e7 100644
--- a/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts
+++ b/apps/client/src/widgets/type_widgets/markdown/completions.spec.ts
@@ -16,7 +16,7 @@ import {
const editorUtils = vi.hoisted(() => ({
uploadImageAndInsert: vi.fn(),
insertDateTime: vi.fn(),
- showAddLinkDialog: vi.fn(),
+ showEditLinkDialog: vi.fn(),
showIncludeNoteDialog: vi.fn()
}));
vi.mock("./editor_utils", async (importOriginal) => ({
@@ -318,8 +318,8 @@ describe("buildMarkdownCommands", () => {
expect(run("date", "On /date")).toBe("On ");
expect(run("link", "See /link")).toBe("See ");
expect(run("include", "/include")).toBe("");
- const { insertDateTime, showAddLinkDialog, showIncludeNoteDialog } = editorUtils;
- for (const action of [ insertDateTime, showAddLinkDialog, showIncludeNoteDialog ]) {
+ const { insertDateTime, showEditLinkDialog, showIncludeNoteDialog } = editorUtils;
+ for (const action of [ insertDateTime, showEditLinkDialog, showIncludeNoteDialog ]) {
expect(action).toHaveBeenCalledExactlyOnceWith(editor);
}
});
diff --git a/apps/client/src/widgets/type_widgets/markdown/completions.tsx b/apps/client/src/widgets/type_widgets/markdown/completions.tsx
index d430d85fee..a93061815e 100644
--- a/apps/client/src/widgets/type_widgets/markdown/completions.tsx
+++ b/apps/client/src/widgets/type_widgets/markdown/completions.tsx
@@ -29,7 +29,7 @@ import type { CompletionMatch, SlashCommand } from "../code/editor_completions";
import { SLASH_COMMAND_REGEX } from "../code/snippets";
import SAMPLE_DIAGRAMS from "../mermaid/sample_diagrams";
import {
- insertDateTime, showAddLinkDialog, showIncludeNoteDialog, uploadImageAndInsert
+ insertDateTime, showEditLinkDialog, showIncludeNoteDialog, uploadImageAndInsert
} from "./editor_utils";
/** What the Markdown commands are built from, read again each time the list looks them up. */
@@ -122,7 +122,7 @@ export function buildMarkdownCommands(
description: t("markdown_slash_commands.link"),
aliases: [ "internal link", "trilium link", "reference link" ],
iconSvg: internalLinkIcon
- }, runAction(showAddLinkDialog)),
+ }, runAction(showEditLinkDialog)),
command("math", {
title: t("markdown_slash_commands.titles.math"),
description: t("markdown_slash_commands.math"),
diff --git a/apps/client/src/widgets/type_widgets/markdown/editor_utils.ts b/apps/client/src/widgets/type_widgets/markdown/editor_utils.ts
index 69774ccb7b..7036fb7cea 100644
--- a/apps/client/src/widgets/type_widgets/markdown/editor_utils.ts
+++ b/apps/client/src/widgets/type_widgets/markdown/editor_utils.ts
@@ -52,12 +52,12 @@ export async function uploadImageAndInsert(view: VanillaCodeMirror, note: FNote,
toast.showError(detail ? `${base} ${detail}` : base);
}
-/** Opens the add link dialog, then puts the link picked in place of the selection of `view`. */
-export function showAddLinkDialog(view: VanillaCodeMirror) {
+/** Opens the edit link dialog, then puts the link picked in place of the selection of `view`. */
+export function showEditLinkDialog(view: VanillaCodeMirror) {
const { from, to } = view.state.selection.main;
const selectedText = view.state.sliceDoc(from, to);
- void appContext.triggerCommand("showAddLinkDialog", {
+ void appContext.triggerCommand("showEditLinkDialog", {
text: selectedText,
hasSelection: from !== to,
async addLink(notePath: string, linkTitle: string | null, externalLink?: boolean) {
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
index 8341746897..b4ff951d09 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
@@ -6,7 +6,7 @@ import { describe, expect, it, onTestFinished, vi } from "vitest";
import appContext from "../../../components/app_context";
import { buildNotes } from "../../../test/easy-froca";
import { renderInto } from "../../../test/render";
-import type { AddLinkOpts } from "../../dialogs/add_link";
+import type { EditLinkOpts } from "../../dialogs/edit_link";
import { uploadNodeImage } from "./images";
import NodePanel, { applyTagTexts, DEFAULT_FONT_SIZE, gatherTags, getCommonValue, MIXED, NODE_BACKGROUND_COLORS, NODE_COLORS, withIconAt } from "./NodePanel";
@@ -773,7 +773,7 @@ describe("NodePanel", () => {
await vi.waitFor(() => expect(linkLabel(note)).toBe("Linked note"));
});
- it("picks a link through the add-link dialog, asked for the target alone", async () => {
+ it("picks a link through the edit link dialog, asked for the target alone", async () => {
const nodes = [buildNode({ id: "a" }), buildNode({ id: "b" })];
const { mind, reshapeNode } = buildMind(nodes);
const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockReturnValue(undefined);
@@ -784,12 +784,12 @@ describe("NodePanel", () => {
// A node reads as its own topic, so the dialog is asked for what is pointed at and nothing
// else — no title to write beside it.
- expect(triggerCommand).toHaveBeenCalledWith("showAddLinkDialog",
+ expect(triggerCommand).toHaveBeenCalledWith("showEditLinkDialog",
expect.objectContaining({ targetOnly: true, hasSelection: false }));
// What comes back is stored the way the map stores it: a note as an in-app address, an
// address as one we could follow. Every node the panel was handed takes it.
- const opts = triggerCommand.mock.calls[0][1] as AddLinkOpts;
+ const opts = triggerCommand.mock.calls[0][1] as EditLinkOpts;
await opts.addLink("root/abc123", "Linked note");
expect(reshapeNode).toHaveBeenNthCalledWith(1, mind.currentNodes[0], { hyperLink: "#root/abc123" });
expect(reshapeNode).toHaveBeenNthCalledWith(2, mind.currentNodes[1], { hyperLink: "#root/abc123" });
@@ -810,7 +810,7 @@ describe("NodePanel", () => {
const openOn = (...nodes: NodeObj[]) => {
linkField(renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />))?.click();
- return (triggerCommand.mock.lastCall?.[1] as AddLinkOpts).currentLink;
+ return (triggerCommand.mock.lastCall?.[1] as EditLinkOpts).currentLink;
};
// Handed over as the pick it was, so that the dialog opens on it and offers to change it.
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
index 14e9e9246f..3f55ad38af 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
@@ -564,7 +564,7 @@ function buildImageShapeOptions() {
/**
* The link a node carries: a note, or a page outside Trilium — one field, a node carrying one link.
*
- * What the field opens is the add-link dialog every other link in Trilium is picked through, asked
+ * What the field opens is the edit link dialog every other link in Trilium is picked through, asked
* for the target alone (`targetOnly` among its options): a node reads as its own topic, so there is
* no title to write beside it. A dialog rather than a menu hung off the field, which is where the
* picker used to sit — the panel stands in the corner of the map, and a menu anchored there had a
@@ -586,7 +586,7 @@ function NodeLink({ currentValue, indeterminate, onChange }: {
className="mind-map-node-link"
text={<NodeLinkFace link={currentValue} indeterminate={indeterminate} />}
title={t("mind-map.choose-link")}
- onClick={() => void appContext.triggerCommand("showAddLinkDialog", {
+ onClick={() => void appContext.triggerCommand("showEditLinkDialog", {
text: "",
hasSelection: false,
targetOnly: true,
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 ecd603c4cc..24945f2611 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts
@@ -43,7 +43,7 @@ vi.mock("./utils", async (importOriginal) => ({
const {
applyPendingAttachmentChanges,
- getAddLinkOpts,
+ getEditLinkOpts,
getBlockData,
isCaretInFocus,
notifyAttachmentChanges,
@@ -455,7 +455,7 @@ describe("parseLinkHref", () => {
});
});
-describe("getAddLinkOpts", () => {
+describe("getEditLinkOpts", () => {
function createApi(currentLink: LinkAtSelection | null, anchors: string[] = []) {
return {
hasSelection: vi.fn(() => true),
@@ -477,7 +477,7 @@ describe("getAddLinkOpts", () => {
const api = createApi({
href: "#root/abc?bookmark=part", text: "See there", display: "plain"
});
- const opts = getAddLinkOpts(api, ready);
+ const opts = getEditLinkOpts(api, ready);
expect(opts).toMatchObject({
text: "See there", hasSelection: false, currentTitle: "See there",
currentLink: { notePath: "root/abc" }, currentBookmark: "part", display: "plain"
@@ -494,7 +494,7 @@ describe("getAddLinkOpts", () => {
it("edits a selected link preview as a web link titled by its title, shown as it is", () => {
const api = createApi({ href: "https://example.com", text: "Example", display: "card" });
- expect(getAddLinkOpts(api, ready, { display: "inline" })).toMatchObject({
+ expect(getEditLinkOpts(api, ready, { display: "inline" })).toMatchObject({
currentLink: { externalLink: "https://example.com" }, currentTitle: "Example",
display: "card"
});
@@ -502,7 +502,7 @@ describe("getAddLinkOpts", () => {
it("adds a link from the selection outside one", async () => {
const api = createApi(null);
- const opts = getAddLinkOpts(api, ready);
+ const opts = getEditLinkOpts(api, ready);
expect(opts).toMatchObject({ text: "chosen words", hasSelection: true });
expect(opts.currentLink).toBeUndefined();
@@ -516,12 +516,12 @@ describe("getAddLinkOpts", () => {
});
it("offers the document's anchors, and edits a link to one of them as that anchor", () => {
- expect(getAddLinkOpts(createApi(null, [ "intro" ]), ready)).toMatchObject({
+ expect(getEditLinkOpts(createApi(null, [ "intro" ]), ready)).toMatchObject({
anchors: [ "intro" ]
});
const api = createApi({ href: "#intro", text: "Start", display: "plain" }, [ "intro" ]);
- const opts = getAddLinkOpts(api, ready);
+ const opts = getEditLinkOpts(api, ready);
expect(opts).toMatchObject({
anchors: [ "intro" ], currentAnchor: "intro", currentTitle: "Start"
});
@@ -529,9 +529,9 @@ describe("getAddLinkOpts", () => {
});
it("opens a new link on the side and with the display it is asked for", () => {
- const opts = getAddLinkOpts(createApi(null), ready, { target: "url", display: "embed" });
+ const opts = getEditLinkOpts(createApi(null), ready, { target: "url", display: "embed" });
expect(opts).toMatchObject({ target: "url", display: "embed" });
- expect(getAddLinkOpts(createApi(null), ready)).toMatchObject({
+ expect(getEditLinkOpts(createApi(null), ready)).toMatchObject({
target: undefined, display: undefined
});
});
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index c71dfda3e4..c48858c5d0 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -26,7 +26,7 @@ import note_create from "../../../services/note_create";
import { consumeSearchTerms } from "../../../services/search_jump";
import toast from "../../../services/toast";
import utils, { isMobile } from "../../../services/utils";
-import { AddLinkBalloon, type AddLinkOpts } from "../../dialogs/add_link";
+import { EditLinkBalloon, type EditLinkOpts } from "../../dialogs/edit_link";
import {
useEditorSpacedUpdate, useLegacyImperativeHandlers, useNoteLabel, useSameNoteSwitch,
useSearchTermsConsumer, useTriliumEvent, useTriliumOption, useTriliumOptionBool
@@ -250,18 +250,18 @@ export default function EditableText({
};
const [ linkDialog, setLinkDialog ] = useState<{
- opts: AddLinkOpts;
+ opts: EditLinkOpts;
request: LinkDialogRequest;
} | null>(null);
- // CKEditor places the balloon at the caret; `AddLinkBalloon` renders into its container.
- // On mobile, `showAddLinkDialog` opens the form in a modal instead.
+ // CKEditor places the balloon at the caret; `EditLinkBalloon` renders into its container.
+ // On mobile, `showEditLinkDialog` opens the form in a modal instead.
function showLinkDialog(request: LinkDialogRequest) {
if (!editorApiRef.current) return null;
- const opts = getAddLinkOpts(editorApiRef.current, waitForEditor, request);
+ const opts = getEditLinkOpts(editorApiRef.current, waitForEditor, request);
if (isMobile()) {
- parentComponent?.triggerCommand("showAddLinkDialog", opts);
+ parentComponent?.triggerCommand("showEditLinkDialog", opts);
return null;
}
@@ -574,7 +574,7 @@ export default function EditableText({
/>}
{linkDialog && createPortal(
- <AddLinkBalloon opts={linkDialog.opts} onClose={linkDialog.request.close} />,
+ <EditLinkBalloon opts={linkDialog.opts} onClose={linkDialog.request.close} />,
linkDialog.request.container
)}
</>
@@ -586,13 +586,13 @@ export default function EditableText({
* now. An empty editor still holds a block, whose id keeps the place of the blocks in the note.
*/
/**
- * What the Add link dialog opens on: the link around the caret or the selected link preview, which
+ * What the edit link dialog opens on: the link around the caret or the selected link preview, which
* saving rewrites, or a new link at the selection, on the `target` side and shown as `display`.
*/
-export function getAddLinkOpts(
+export function getEditLinkOpts(
api: CKEditorApi, ready: () => Promise<unknown>,
- { target, display }: Pick<AddLinkOpts, "target" | "display"> = {}
-): AddLinkOpts {
+ { target, display }: Pick<EditLinkOpts, "target" | "display"> = {}
+): EditLinkOpts {
async function addLinkPreview(...args: Parameters<CKEditorApi["addLinkPreview"]>) {
await ready();
api.addLinkPreview(...args);
@@ -631,12 +631,12 @@ export function getAddLinkOpts(
}
/**
- * What a link's `href` opens the Add link dialog on: one of the document's `anchors`, the note
+ * What a link's `href` opens the edit link dialog on: one of the document's `anchors`, the note
* with the anchor it points at, or the address.
*/
export function parseLinkHref(
href: string, anchors: string[] = []
-): Pick<AddLinkOpts, "currentLink" | "currentBookmark" | "currentAnchor"> {
+): Pick<EditLinkOpts, "currentLink" | "currentBookmark" | "currentAnchor"> {
if (href.startsWith("#") && anchors.includes(href.slice(1))) {
return { currentAnchor: href.slice(1) };
}
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 b0678269f7..b0ab169ed6 100644
--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts
@@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from
import imageService from "../../../services/image.js";
import linkService from "../../../services/link.js";
import { ensureMimeTypesForHighlighting } from "../../../services/syntax_highlight.js";
-import type { AddLinkOpts } from "../../dialogs/add_link.js";
+import type { EditLinkOpts } from "../../dialogs/edit_link.js";
import { FLOATING_LAYER_SELECTOR } from "../../react/floating_layers.js";
import { buildConfig, type BuildEditorOptions, OPEN_SOURCE_LICENSE_KEY } from "./config.js";
@@ -562,10 +562,10 @@ describe("CK config - tables", () => {
referenceLink?.fixLink?.("Gone", fix);
- expect(triggerHostCommand).toHaveBeenCalledExactlyOnceWith("showAddLinkDialog", expect.objectContaining({
+ expect(triggerHostCommand).toHaveBeenCalledExactlyOnceWith("showEditLinkDialog", expect.objectContaining({
text: "Gone", hasSelection: false, fixLink: true
}));
- const [ , dialog ] = triggerHostCommand.mock.calls[0] as unknown as [ string, AddLinkOpts ];
+ const [ , dialog ] = triggerHostCommand.mock.calls[0] as unknown as [ string, EditLinkOpts ];
await dialog.addLink("root/n9", null);
expect(fix).toHaveBeenCalledExactlyOnceWith("#root/n9");
});
diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.ts
index e0af95d9c4..20a3d23a87 100644
--- a/apps/client/src/widgets/type_widgets/text/config.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.ts
@@ -252,7 +252,7 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi
void linkService.loadReferenceLinkTitle($(element), href, opts.getNoteId?.(), storedTitle);
},
fixLink: (storedTitle, fix) => {
- void opts.triggerHostCommand?.("showAddLinkDialog", {
+ void opts.triggerHostCommand?.("showEditLinkDialog", {
text: storedTitle,
hasSelection: false,
fixLink: true,
diff --git a/apps/server/e2e/add_link_double_enter.spec.ts b/apps/server/e2e/edit_link_double_enter.spec.ts
similarity index 91%
rename from apps/server/e2e/add_link_double_enter.spec.ts
rename to apps/server/e2e/edit_link_double_enter.spec.ts
index 137ce7b43b..79d1c4a752 100644
--- a/apps/server/e2e/add_link_double_enter.spec.ts
+++ b/apps/server/e2e/edit_link_double_enter.spec.ts
@@ -12,7 +12,7 @@ import App from "../../../packages/trilium-e2e/src/support/app";
//
// Dispatching both Enter keydowns in a single synchronous task makes the race
// deterministic: no render can run between them.
-test("fast double-Enter in add-link dialog is not consumed by a stale suggestion", async ({ page, context }) => {
+test("fast double-Enter in the edit link dialog is not consumed by a stale suggestion", async ({ page, context }) => {
const app = new App(page, context);
await app.goto();
@@ -23,7 +23,7 @@ test("fast double-Enter in add-link dialog is not consumed by a stale suggestion
await editor.click();
await page.keyboard.press("Control+l");
- const dialog = page.locator(".add-link-dialog");
+ const dialog = page.locator(".edit-link-dialog");
await expect(dialog).toBeVisible();
const input = dialog.locator("input.note-autocomplete");
@@ -40,7 +40,7 @@ test("fast double-Enter in add-link dialog is not consumed by a stale suggestion
// Fire both Enters in one synchronous task — zero timers can interleave —
// and record what each one did.
const result = await page.evaluate(() => {
- const el = document.querySelector<HTMLInputElement>(".add-link-dialog input.note-autocomplete");
+ const el = document.querySelector<HTMLInputElement>(".edit-link-dialog input.note-autocomplete");
if (!el) throw new Error("autocomplete input not found");
const fire = () => {
diff --git a/packages/ckeditor5/src/plugins/internallink.spec.ts b/packages/ckeditor5/src/plugins/internallink.spec.ts
index 3b9532c88b..03340ca8b7 100644
--- a/packages/ckeditor5/src/plugins/internallink.spec.ts
+++ b/packages/ckeditor5/src/plugins/internallink.spec.ts
@@ -48,7 +48,7 @@ describe("InternalLinkPlugin", () => {
editor.execute(COMMAND_NAME, { target: "url" });
const container = shown.request?.container;
expect(shown.request?.target).toBe("url");
- expect(container?.classList.contains("add-link-balloon")).toBe(true);
+ expect(container?.classList.contains("edit-link-balloon")).toBe(true);
expect(container && balloon.view.element?.contains(container)).toBe(true);
shown.request?.close();
diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.ts
index 6d907061d2..0268cde7ea 100644
--- a/packages/ckeditor5/src/plugins/internallink.ts
+++ b/packages/ckeditor5/src/plugins/internallink.ts
@@ -39,7 +39,7 @@ export default class InternalLinkPlugin extends Plugin {
return [ ReferenceLink, ContextualBalloon ];
}
- private dialog = new HostedBalloon(this.editor, 'add-link-balloon');
+ private dialog = new HostedBalloon(this.editor, 'edit-link-balloon');
init() {
const editor = this.editor;