Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Unify link insertion and editing flows (#1589)

Dimitri POSTOLOV48dbc151f2ec
diff --git a/docs/next-env.d.ts b/docs/next-env.d.ts
index c4b7818fb..9edff1c7c 100644
--- a/docs/next-env.d.ts
+++ b/docs/next-env.d.ts
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
-import "./.next/dev/types/routes.d.ts";
+import "./.next/types/routes.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
diff --git a/packages/app/src/components/NewItemDialog.tsx b/packages/app/src/components/NewItemDialog.tsx
index fa3914fa4..105224f51 100644
--- a/packages/app/src/components/NewItemDialog.tsx
+++ b/packages/app/src/components/NewItemDialog.tsx
@@ -301,119 +301,115 @@ export function NewItemDialog({
</DialogDescription>
</DialogHeader>
- <DialogBody>
- <div className="space-y-6">
- {showTemplatePicker && (
- <div className="flex flex-col gap-2">
- {/*
- * No `htmlFor` on the label — the trigger is a button with
- * role="combobox" + a self-referencing aria-labelledby
- * ("<label> <trigger>") that concatenates the static "Start
- * from" label with the button's own selected-value text. A
- * label/htmlFor pair on a button only forwards click → focus,
- * not click → open, so it'd surprise users carrying intuition
- * from native <select>.
- */}
- <span id={templatePickerLabelId} className="text-sm font-medium">
- <Trans>Start from</Trans>
- </span>
- {templatesError ? (
- <p role="alert" className="text-1sm text-destructive">
- <Trans>
- Could not load templates: {templatesError}. You can still create a blank note.
- </Trans>
- </p>
- ) : null}
- <TemplatePickerCombobox
- triggerId={templatePickerTriggerId}
- labelledById={templatePickerLabelId}
- open={templatePickerOpen}
- onOpenChange={setTemplatePickerOpen}
- value={selectedTemplate}
- onValueChange={(next) => {
- setSelectedTemplate(next);
- setTemplateUserPicked(true);
- }}
- templates={templates}
- loading={templatesLoading}
- />
- {!templatesLoading && !templatesError && templates.length === 0 ? (
- <p className="text-1sm text-muted-foreground">
- <Trans>
- No templates yet. Add one in this folder's Templates section, or in Settings →
- Templates.
- </Trans>
- </p>
- ) : null}
- </div>
- )}
- {kind === 'folder' && (
- <div className="flex flex-col gap-2">
- <label className="text-sm font-medium" htmlFor={folderInputId}>
- <Trans>Folder name</Trans>
- </label>
- <Input
- ref={folderInputRef}
- id={folderInputId}
- value={folderName}
- onChange={(e) => {
- setFolderName(e.target.value);
- setError(null);
- }}
- placeholder="folder-name"
- autoFocus
- aria-describedby={
- error && (errorField === 'folder' || errorField === 'form')
- ? errorId
- : undefined
- }
- aria-invalid={
- error && (errorField === 'folder' || errorField === 'form') ? true : undefined
- }
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- e.preventDefault();
- const folderErr = validatePath(folderName.trim());
- if (folderErr) {
- const detail = t(pathErrorDescriptor(folderErr));
- setError(t`Folder name: ${detail}`);
- setErrorField('folder');
- return;
- }
- fileInputRef.current?.focus();
- }
- }}
- />
- </div>
- )}
+ <DialogBody className="space-y-6 pb-1">
+ {showTemplatePicker && (
+ <div className="flex flex-col gap-2">
+ {/*
+ * No `htmlFor` on the label — the trigger is a button with
+ * role="combobox" + a self-referencing aria-labelledby
+ * ("<label> <trigger>") that concatenates the static "Start
+ * from" label with the button's own selected-value text. A
+ * label/htmlFor pair on a button only forwards click → focus,
+ * not click → open, so it'd surprise users carrying intuition
+ * from native <select>.
+ */}
+ <span id={templatePickerLabelId} className="text-sm font-medium">
+ <Trans>Start from</Trans>
+ </span>
+ {templatesError ? (
+ <p role="alert" className="text-1sm text-destructive">
+ <Trans>
+ Could not load templates: {templatesError}. You can still create a blank note.
+ </Trans>
+ </p>
+ ) : null}
+ <TemplatePickerCombobox
+ triggerId={templatePickerTriggerId}
+ labelledById={templatePickerLabelId}
+ open={templatePickerOpen}
+ onOpenChange={setTemplatePickerOpen}
+ value={selectedTemplate}
+ onValueChange={(next) => {
+ setSelectedTemplate(next);
+ setTemplateUserPicked(true);
+ }}
+ templates={templates}
+ loading={templatesLoading}
+ />
+ {!templatesLoading && !templatesError && templates.length === 0 ? (
+ <p className="text-1sm text-muted-foreground">
+ <Trans>
+ No templates yet. Add one in this folder's Templates section, or in Settings →
+ Templates.
+ </Trans>
+ </p>
+ ) : null}
+ </div>
+ )}
+ {kind === 'folder' && (
<div className="flex flex-col gap-2">
- <label className="text-sm font-medium" htmlFor={fileInputId}>
- {kind === 'folder' ? <Trans>First file name</Trans> : <Trans>File name</Trans>}
+ <label className="text-sm font-medium" htmlFor={folderInputId}>
+ <Trans>Folder name</Trans>
</label>
<Input
- ref={fileInputRef}
- id={fileInputId}
- value={fileName}
- onChange={(e) => handleFileNameChange(e.target.value)}
- placeholder="my-note"
- autoFocus={kind === 'file'}
+ ref={folderInputRef}
+ id={folderInputId}
+ value={folderName}
+ onChange={(e) => {
+ setFolderName(e.target.value);
+ setError(null);
+ }}
+ placeholder="folder-name"
+ autoFocus
aria-describedby={
- error && (errorField === 'file' || errorField === 'form') ? errorId : undefined
+ error && (errorField === 'folder' || errorField === 'form') ? errorId : undefined
}
aria-invalid={
- error && (errorField === 'file' || errorField === 'form') ? true : undefined
+ error && (errorField === 'folder' || errorField === 'form') ? true : undefined
}
- onFocus={(e) => selectBasename(e.currentTarget)}
onKeyDown={(e) => {
- if (e.key === 'Enter' && !isSubmitDisabled) void handleCreate();
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ const folderErr = validatePath(folderName.trim());
+ if (folderErr) {
+ const detail = t(pathErrorDescriptor(folderErr));
+ setError(t`Folder name: ${detail}`);
+ setErrorField('folder');
+ return;
+ }
+ fileInputRef.current?.focus();
+ }
}}
/>
- {error && (
- <p id={errorId} role="alert" className="text-1sm text-destructive">
- {error}
- </p>
- )}
</div>
+ )}
+ <div className="flex flex-col gap-2">
+ <label className="text-sm font-medium" htmlFor={fileInputId}>
+ {kind === 'folder' ? <Trans>First file name</Trans> : <Trans>File name</Trans>}
+ </label>
+ <Input
+ ref={fileInputRef}
+ id={fileInputId}
+ value={fileName}
+ onChange={(e) => handleFileNameChange(e.target.value)}
+ placeholder="my-note"
+ autoFocus={kind === 'file'}
+ aria-describedby={
+ error && (errorField === 'file' || errorField === 'form') ? errorId : undefined
+ }
+ aria-invalid={
+ error && (errorField === 'file' || errorField === 'form') ? true : undefined
+ }
+ onFocus={(e) => selectBasename(e.currentTarget)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && !isSubmitDisabled) void handleCreate();
+ }}
+ />
+ {error && (
+ <p id={errorId} role="alert" className="text-1sm text-destructive">
+ {error}
+ </p>
+ )}
</div>
</DialogBody>
diff --git a/packages/app/src/editor/bubble-menu/LinkEditPopover.dom.test.tsx b/packages/app/src/editor/bubble-menu/LinkEditPopover.dom.test.tsx
new file mode 100644
index 000000000..a660e25f3
--- /dev/null
+++ b/packages/app/src/editor/bubble-menu/LinkEditPopover.dom.test.tsx
@@ -0,0 +1,146 @@
+import { afterEach, describe, expect, mock, test } from 'bun:test';
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import type { Editor } from '@tiptap/react';
+import { TooltipProvider } from '@/components/ui/tooltip';
+
+mock.module('@/components/PageListContext', () => ({
+ usePageList: () => ({
+ folderPaths: new Set(['guides']),
+ loading: false,
+ pages: new Set(['guides/install']),
+ }),
+}));
+
+const { LinkEditPopover } = await import('./LinkEditPopover');
+
+const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
+if (typeof globalThis.requestAnimationFrame === 'undefined') {
+ globalThis.requestAnimationFrame = ((callback) => {
+ callback(0);
+ return 0;
+ }) as typeof globalThis.requestAnimationFrame;
+}
+
+function makeEditor({
+ active = true,
+ href = 'https://example.com',
+ onSetLink,
+ onUnsetLink,
+ selectionEmpty = true,
+}: {
+ active?: boolean;
+ href?: string;
+ onSetLink?: (attrs: { href: string }) => void;
+ onUnsetLink?: () => void;
+ selectionEmpty?: boolean;
+} = {}): Editor {
+ const chain = {
+ focus: () => chain,
+ run: () => true,
+ setLink: (attrs: { href: string }) => {
+ onSetLink?.(attrs);
+ return chain;
+ },
+ unsetLink: () => {
+ onUnsetLink?.();
+ return chain;
+ },
+ };
+
+ return {
+ state: { selection: { empty: selectionEmpty } },
+ getAttributes: mock((name: string) => (name === 'link' ? { href } : {})),
+ isActive: mock((name: string) => name === 'link' && active),
+ on: mock(() => {}),
+ off: mock(() => {}),
+ chain: () => chain,
+ } as unknown as Editor;
+}
+
+function renderPopover(editor: Editor) {
+ return render(
+ <TooltipProvider>
+ <LinkEditPopover editor={editor} />
+ </TooltipProvider>,
+ );
+}
+
+afterEach(() => {
+ cleanup();
+ if (nativeRequestAnimationFrame) {
+ globalThis.requestAnimationFrame = nativeRequestAnimationFrame;
+ }
+});
+
+describe('LinkEditPopover', () => {
+ test('prefills the current URL when editing an active collapsed link', () => {
+ renderPopover(makeEditor({ href: 'https://example.com/docs' }));
+
+ fireEvent.mouseDown(screen.getByRole('button', { name: 'Insert link' }));
+
+ expect((screen.getByRole('combobox', { name: 'Link URL' }) as HTMLInputElement).value).toBe(
+ 'https://example.com/docs',
+ );
+ });
+
+ test('starts empty for a non-collapsed selection even when the link mark is active', () => {
+ renderPopover(makeEditor({ href: 'https://example.com/docs', selectionEmpty: false }));
+
+ fireEvent.mouseDown(screen.getByRole('button', { name: 'Insert link' }));
+
+ expect((screen.getByRole('combobox', { name: 'Link URL' }) as HTMLInputElement).value).toBe('');
+ });
+
+ test('applies a trimmed URL with Enter and dismisses the input', () => {
+ const setLink = mock((_attrs: { href: string }) => {});
+ const unsetLink = mock(() => {});
+ renderPopover(makeEditor({ active: false, onSetLink: setLink, onUnsetLink: unsetLink }));
+
+ fireEvent.mouseDown(screen.getByRole('button', { name: 'Insert link' }));
+ const input = screen.getByRole('combobox', { name: 'Link URL' });
+ fireEvent.change(input, { target: { value: ' https://example.com/new ' } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+
+ expect(setLink).toHaveBeenCalledWith({ href: 'https://example.com/new' });
+ expect(unsetLink).not.toHaveBeenCalled();
+ expect(screen.queryByRole('combobox', { name: 'Link URL' })).toBeNull();
+ });
+
+ test('submitting an empty active collapsed link unsets it', async () => {
+ const setLink = mock((_attrs: { href: string }) => {});
+ const unsetLink = mock(() => {});
+ renderPopover(
+ makeEditor({
+ href: '',
+ onSetLink: setLink,
+ onUnsetLink: unsetLink,
+ }),
+ );
+
+ fireEvent.mouseDown(screen.getByRole('button', { name: 'Insert link' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Apply link' }));
+
+ expect(setLink).not.toHaveBeenCalled();
+ await waitFor(() => {
+ expect(unsetLink).toHaveBeenCalled();
+ });
+ await waitFor(() => {
+ expect(screen.queryByRole('combobox', { name: 'Link URL' })).toBeNull();
+ });
+ });
+
+ test('empty inactive input is a no-op and still dismisses', async () => {
+ const setLink = mock((_attrs: { href: string }) => {});
+ const unsetLink = mock(() => {});
+ renderPopover(makeEditor({ active: false, onSetLink: setLink, onUnsetLink: unsetLink }));
+
+ fireEvent.mouseDown(screen.getByRole('button', { name: 'Insert link' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Apply link' }));
+
+ expect(setLink).not.toHaveBeenCalled();
+ expect(unsetLink).not.toHaveBeenCalled();
+ await waitFor(() => {
+ expect(screen.queryByRole('combobox', { name: 'Link URL' })).toBeNull();
+ });
+ });
+});
diff --git a/packages/app/src/editor/bubble-menu/LinkEditPopover.tsx b/packages/app/src/editor/bubble-menu/LinkEditPopover.tsx
index e0233a0d6..bb8c2e37f 100644
--- a/packages/app/src/editor/bubble-menu/LinkEditPopover.tsx
+++ b/packages/app/src/editor/bubble-menu/LinkEditPopover.tsx
@@ -17,9 +17,15 @@ export function LinkEditPopover({ editor }: { editor: Editor }) {
const inputRef = useRef<HTMLInputElement>(null);
const { folderPaths, loading, pages } = usePageList();
- const isLinkActive = editor.isActive('link');
+ const isLinkActive = editor.state.selection.empty && editor.isActive('link');
const currentUrl = editor.getAttributes('link').href ?? '';
+ function getInitialUrlForLinkInput() {
+ return editor.state.selection.empty && editor.isActive('link')
+ ? (editor.getAttributes('link').href ?? '')
+ : '';
+ }
+
useEffect(() => {
function onSelectionUpdate() {
if (editor.state.selection.empty) {
@@ -34,10 +40,9 @@ export function LinkEditPopover({ editor }: { editor: Editor }) {
useEffect(() => {
if (showInput) {
- setUrl(currentUrl);
requestAnimationFrame(() => inputRef.current?.focus());
}
- }, [showInput, currentUrl]);
+ }, [showInput]);
function applyLink() {
if (url.trim()) {
@@ -152,6 +157,7 @@ export function LinkEditPopover({ editor }: { editor: Editor }) {
className={isLinkActive ? 'bg-accent text-primary' : 'text-accent-foreground'}
onMouseDown={(e) => {
e.preventDefault();
+ setUrl(getInitialUrlForLinkInput());
setShowInput(true);
}}
>
diff --git a/packages/app/src/editor/extensions/InternalLinkPropPanel.dom.test.tsx b/packages/app/src/editor/extensions/InternalLinkPropPanel.dom.test.tsx
new file mode 100644
index 000000000..7fb9d4da8
--- /dev/null
+++ b/packages/app/src/editor/extensions/InternalLinkPropPanel.dom.test.tsx
@@ -0,0 +1,233 @@
+import { afterEach, describe, expect, mock, test } from 'bun:test';
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import type { Editor } from '@tiptap/core';
+import { TooltipProvider } from '@/components/ui/tooltip';
+
+if (typeof globalThis.DOMRect === 'undefined') {
+ Object.defineProperty(globalThis, 'DOMRect', {
+ configurable: true,
+ value: class DOMRect {
+ x = 0;
+ y = 0;
+ width = 0;
+ height = 0;
+ top = 0;
+ right = 0;
+ bottom = 0;
+ left = 0;
+ },
+ });
+}
+
+type CurrentMarkInfo = {
+ id: string;
+ markType: string;
+ attrs: { href: string };
+ from: number;
+ to: number;
+};
+
+let currentMarkInfo: CurrentMarkInfo | null = {
+ id: 'm1',
+ markType: 'link',
+ attrs: { href: '' },
+ from: 0,
+ to: 4,
+};
+
+mock.module('../../components/PageListContext', () => ({
+ usePageList: () => ({
+ addPage: () => {},
+ folderPaths: new Set<string>(),
+ loading: false,
+ pages: new Set<string>(),
+ }),
+}));
+
+mock.module('./mark-interaction-bridge', () => ({
+ getCurrentMarkInfo: () => currentMarkInfo,
+}));
+
+mock.module('./use-headings', () => ({
+ useHeadings: () => [],
+}));
+
+const { InternalLinkPropPanel } = await import('./InternalLinkPropPanel');
+const { _resetPendingLinkEditForTest, setPendingLinkEdit } = await import('./link-edit-autoopen');
+
+function makeEditor(
+ options: {
+ onDeleteRange?: (range: { from: number; to: number }) => void;
+ onUpdateAttributes?: (markType: string, attrs: Record<string, unknown>) => void;
+ } = {},
+): Editor {
+ const chain = {
+ focus: () => chain,
+ setTextSelection: () => chain,
+ extendMarkRange: () => chain,
+ deleteRange: (range: { from: number; to: number }) => {
+ options.onDeleteRange?.(range);
+ return chain;
+ },
+ updateAttributes: (markType: string, attrs: Record<string, unknown>) => {
+ options.onUpdateAttributes?.(markType, attrs);
+ return chain;
+ },
+ run: () => true,
+ };
+
+ return {
+ state: {
+ doc: {
+ textBetween: () => 'link',
+ },
+ },
+ chain: () => chain,
+ view: {
+ dom: document.createElement('div'),
+ },
+ } as unknown as Editor;
+}
+
+afterEach(() => {
+ cleanup();
+ _resetPendingLinkEditForTest();
+ currentMarkInfo = {
+ id: 'm1',
+ markType: 'link',
+ attrs: { href: '' },
+ from: 0,
+ to: 4,
+ };
+});
+
+describe('InternalLinkPropPanel', () => {
+ test('renders nothing for empty-href link with no pending edit', () => {
+ const { container } = render(
+ <InternalLinkPropPanel
+ editor={makeEditor()}
+ nodeId="m1"
+ sourceDocName="notes/source"
+ onClose={() => {}}
+ onNavigate={() => false}
+ />,
+ );
+
+ expect(screen.queryByRole('dialog')).toBeNull();
+ expect(container.innerHTML).toBe('');
+ });
+
+ test('auto-opens edit dialog when panel mounts for a pending empty-href link', async () => {
+ setPendingLinkEdit('m1');
+
+ render(
+ <InternalLinkPropPanel
+ editor={makeEditor()}
+ nodeId="m1"
+ sourceDocName="notes/source"
+ onClose={() => {}}
+ onNavigate={() => false}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole('dialog')).toBeDefined();
+ });
+ expect(screen.getByText('Edit markdown link')).toBeDefined();
+ });
+
+ test('deletes the pending empty-href placeholder when the edit dialog is canceled', async () => {
+ const deleteRange = mock((_range: { from: number; to: number }) => {});
+ const onClose = mock(() => {});
+ setPendingLinkEdit('m1');
+
+ render(
+ <InternalLinkPropPanel
+ editor={makeEditor({ onDeleteRange: deleteRange })}
+ nodeId="m1"
+ sourceDocName="notes/source"
+ onClose={onClose}
+ onNavigate={() => false}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole('dialog')).toBeDefined();
+ });
+
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
+
+ await waitFor(() => {
+ expect(deleteRange).toHaveBeenCalledWith({ from: 0, to: 4 });
+ expect(onClose).toHaveBeenCalled();
+ });
+ });
+
+ test('does not delete the pending mark when the edit dialog saves a URL', async () => {
+ const deleteRange = mock((_range: { from: number; to: number }) => {});
+ const onClose = mock(() => {});
+ const updateAttributes = mock((_markType: string, attrs: Record<string, unknown>) => {
+ if (!currentMarkInfo) return;
+ currentMarkInfo = {
+ ...currentMarkInfo,
+ attrs: { href: typeof attrs.href === 'string' ? attrs.href : '' },
+ };
+ });
+ setPendingLinkEdit('m1');
+
+ render(
+ <TooltipProvider>
+ <InternalLinkPropPanel
+ editor={makeEditor({ onDeleteRange: deleteRange, onUpdateAttributes: updateAttributes })}
+ nodeId="m1"
+ sourceDocName="notes/source"
+ onClose={onClose}
+ onNavigate={() => false}
+ />
+ </TooltipProvider>,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole('dialog')).toBeDefined();
+ });
+
+ fireEvent.change(screen.getByRole('combobox', { name: 'Link target' }), {
+ target: { value: 'https://example.com' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
+
+ await waitFor(() => {
+ expect(updateAttributes).toHaveBeenCalledWith('link', { href: 'https://example.com' });
+ });
+ expect(deleteRange).not.toHaveBeenCalled();
+ expect(onClose).not.toHaveBeenCalled();
+ });
+
+ test('closes without deleting when the pending mark was already removed remotely', async () => {
+ const deleteRange = mock((_range: { from: number; to: number }) => {});
+ const onClose = mock(() => {});
+ setPendingLinkEdit('m1');
+
+ render(
+ <InternalLinkPropPanel
+ editor={makeEditor({ onDeleteRange: deleteRange })}
+ nodeId="m1"
+ sourceDocName="notes/source"
+ onClose={onClose}
+ onNavigate={() => false}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole('dialog')).toBeDefined();
+ });
+
+ currentMarkInfo = null;
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
+
+ await waitFor(() => {
+ expect(onClose).toHaveBeenCalled();
+ });
+ expect(deleteRange).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/app/src/editor/extensions/InternalLinkPropPanel.tsx b/packages/app/src/editor/extensions/InternalLinkPropPanel.tsx
index a6e1ac351..4a7ec4d77 100644
--- a/packages/app/src/editor/extensions/InternalLinkPropPanel.tsx
+++ b/packages/app/src/editor/extensions/InternalLinkPropPanel.tsx
@@ -34,7 +34,11 @@ import {
handleChipLinkClick,
toInternalHashHref,
} from '../internal-link-helpers';
-import { type LinkPathSuggestion, LinkPathSuggestionInput } from '../link-path-suggestions';
+import {
+ type LinkPathSuggestion,
+ LinkPathSuggestionInput,
+ preventLinkPathSuggestionDialogDismiss,
+} from '../link-path-suggestions';
import { isSafeNavigationUrl } from '../safe-navigation-url';
import { CopyButton } from './LinkPropPanelCopy';
import { consumePendingLinkEdit } from './link-edit-autoopen';
@@ -152,7 +156,13 @@ function EditMarkdownLinkDialog({
return (
<Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="sm:max-w-xl" data-ok-layer-spawned="">
+ <DialogContent
+ className="sm:max-w-xl"
+ data-ok-layer-spawned=""
+ onPointerDownOutside={preventLinkPathSuggestionDialogDismiss}
+ onFocusOutside={preventLinkPathSuggestionDialogDismiss}
+ onInteractOutside={preventLinkPathSuggestionDialogDismiss}
+ >
<DialogHeader>
<DialogTitle>
<Trans>Edit markdown link</Trans>
@@ -162,63 +172,61 @@ function EditMarkdownLinkDialog({
</DialogDescription>
</DialogHeader>
- <DialogBody>
- <div className="space-y-6">
- <div>
- <label className="mb-1.5 block text-sm font-medium" htmlFor={targetId}>
- {docTargetMode ? <Trans>Page</Trans> : <Trans>Link target</Trans>}
- </label>
- <LinkPathSuggestionInput
- id={targetId}
- value={editTarget}
- pages={pages}
- folderPaths={folderPaths}
- loading={loading}
- onValueChange={(nextValue) => {
- setEditTarget(nextValue);
- setEditMode((current) => getMarkdownLinkEditMode(nextValue, current));
- }}
- onSuggestionSelect={handlePathSuggestionSelect}
- placeholder={t`guides/install or https://example.com`}
- autoFocus
- onKeyDown={handleKeyDown}
- />
- </div>
+ <DialogBody className="space-y-6 pb-1">
+ <div>
+ <label className="mb-1.5 inline-block text-sm font-medium" htmlFor={targetId}>
+ {docTargetMode ? <Trans>Page</Trans> : <Trans>Link target</Trans>}
+ </label>
+ <LinkPathSuggestionInput
+ id={targetId}
+ value={editTarget}
+ pages={pages}
+ folderPaths={folderPaths}
+ loading={loading}
+ onValueChange={(nextValue) => {
+ setEditTarget(nextValue);
+ setEditMode((current) => getMarkdownLinkEditMode(nextValue, current));
+ }}
+ onSuggestionSelect={handlePathSuggestionSelect}
+ placeholder={t`guides/install or https://example.com`}
+ autoFocus
+ onKeyDown={handleKeyDown}
+ />
+ </div>
+
+ <div>
+ <label className="mb-1.5 inline-block text-sm font-medium" htmlFor={labelId}>
+ <Trans>
+ Label <span className="font-normal text-muted-foreground">(visible link text)</span>
+ </Trans>
+ </label>
+ <Input
+ id={labelId}
+ value={editLabel}
+ onChange={(e) => setEditLabel(e.target.value)}
+ placeholder={t`Display text`}
+ onKeyDown={handleKeyDown}
+ />
+ </div>
+ {docTargetMode ? (
<div>
- <label className="mb-1.5 block text-sm font-medium" htmlFor={labelId}>
+ <label className="mb-1.5 inline-block text-sm font-medium" htmlFor={anchorId}>
<Trans>
- Label{' '}
- <span className="font-normal text-muted-foreground">(visible link text)</span>
+ Section{' '}
+ <span className="font-normal text-muted-foreground">
+ (optional heading anchor)
+ </span>
</Trans>
</label>
<Input
- id={labelId}
- value={editLabel}
- onChange={(e) => setEditLabel(e.target.value)}
- placeholder={t`Display text`}
+ id={anchorId}
+ value={editAnchor}
+ onChange={(e) => setEditAnchor(e.target.value)}
+ placeholder={t`heading-slug`}
onKeyDown={handleKeyDown}
/>
- </div>
-
- {docTargetMode ? (
- <div>
- <label className="mb-1.5 block text-sm font-medium" htmlFor={anchorId}>
- <Trans>
- Section{' '}
- <span className="font-normal text-muted-foreground">
- (optional heading anchor)
- </span>
- </Trans>
- </label>
- <Input
- id={anchorId}
- value={editAnchor}
- onChange={(e) => setEditAnchor(e.target.value)}
- placeholder={t`heading-slug`}
- onKeyDown={handleKeyDown}
- />
- {/*
+ {/*
Heading-list is plain click-to-toggle buttons — not a
WAI-ARIA listbox. Previously declared role="listbox" /
role="option" but lacked the matching keyboard model
@@ -226,36 +234,33 @@ function EditMarkdownLinkDialog({
role + missing keyboard model as a conflict; native
button semantics already match the actual interaction.
*/}
- {showHeadings ? (
- <div
- id={headingListId}
- className="mt-1.5 max-h-36 overflow-y-auto subtle-scrollbar rounded-md border border-border bg-muted/30"
- >
- {headings.map((heading) => (
- <button
- key={`${heading.slug}-${heading.level}-${heading.text}`}
- type="button"
- aria-pressed={editAnchor === heading.slug}
- className={cn(
- 'flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground',
- editAnchor === heading.slug && 'bg-accent text-accent-foreground',
- )}
- style={{ paddingLeft: `${(heading.level - 1) * 12 + 8}px` }}
- onClick={() =>
- setEditAnchor(editAnchor === heading.slug ? '' : heading.slug)
- }
- >
- <span className="w-7 shrink-0 font-mono text-[10px] text-muted-foreground">
- H{heading.level}
- </span>
- <span className="truncate">{heading.text}</span>
- </button>
- ))}
- </div>
- ) : null}
- </div>
- ) : null}
- </div>
+ {showHeadings ? (
+ <div
+ id={headingListId}
+ className="mt-1.5 max-h-36 overflow-y-auto subtle-scrollbar rounded-md border border-border bg-muted/30"
+ >
+ {headings.map((heading) => (
+ <button
+ key={`${heading.slug}-${heading.level}-${heading.text}`}
+ type="button"
+ aria-pressed={editAnchor === heading.slug}
+ className={cn(
+ 'flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground',
+ editAnchor === heading.slug && 'bg-accent text-accent-foreground',
+ )}
+ style={{ paddingLeft: `${(heading.level - 1) * 12 + 8}px` }}
+ onClick={() => setEditAnchor(editAnchor === heading.slug ? '' : heading.slug)}
+ >
+ <span className="w-7 shrink-0 font-mono text-[10px] text-muted-foreground">
+ H{heading.level}
+ </span>
+ <span className="truncate">{heading.text}</span>
+ </button>
+ ))}
+ </div>
+ ) : null}
+ </div>
+ ) : null}
</DialogBody>
<DialogFooter>
@@ -301,22 +306,12 @@ export function InternalLinkPropPanel({
const { addPage, folderPaths, pages, loading } = usePageList();
const { t } = useLingui();
- if (!info || !href) {
+ if (!info) {
return null;
}
- const target = classifyMarkdownHref(href, sourceDocName);
-
- const displayHref =
- target?.kind === 'doc'
- ? `${target.docName}${target.anchor ? `#${target.anchor}` : ''}`
- : target?.kind === 'anchor'
- ? `#${target.anchor}`
- : target?.kind === 'external'
- ? target.url
- : href;
-
const linkText = editor.state.doc.textBetween(info.from, info.to);
+ const target = href ? classifyMarkdownHref(href, sourceDocName) : null;
function handleSave(nextHref: string, nextText: string, labelChanged: boolean) {
const live = getCurrentMarkInfo(editor.state, nodeId);
@@ -351,6 +346,51 @@ export function InternalLinkPropPanel({
onClose();
}
+ function handleEmptyHrefDialogOpenChange(open: boolean) {
+ if (open) {
+ setEditDialogOpen(true);
+ return;
+ }
+
+ const live = getCurrentMarkInfo(editor.state, nodeId);
+ const liveHref = (live?.attrs?.href as string | undefined) ?? '';
+ if (liveHref) {
+ setEditDialogOpen(false);
+ return;
+ }
+
+ if (live) {
+ editor.chain().focus().deleteRange({ from: live.from, to: live.to }).run();
+ }
+ onClose();
+ }
+
+ const editDialog = (
+ <EditMarkdownLinkDialog
+ open={editDialogOpen}
+ href={href}
+ text={linkText}
+ pages={pages}
+ folderPaths={folderPaths}
+ loading={loading}
+ onOpenChange={href ? setEditDialogOpen : handleEmptyHrefDialogOpenChange}
+ onSave={handleSave}
+ />
+ );
+
+ if (!href) {
+ return <>{editDialog}</>;
+ }
+
+ const displayHref =
+ target?.kind === 'doc'
+ ? `${target.docName}${target.anchor ? `#${target.anchor}` : ''}`
+ : target?.kind === 'anchor'
+ ? `#${target.anchor}`
+ : target?.kind === 'external'
+ ? target.url
+ : href;
+
function updateMissingLinkHref(docName: string) {
const live = getCurrentMarkInfo(editor.state, nodeId);
if (!live) return;
@@ -497,6 +537,8 @@ export function InternalLinkPropPanel({
return (
<>
+ {editDialog}
+
<InteractionPropPanel
kind="internal-link"
ariaLabel={`${stateLabel.text}: ${displayHref}`}
@@ -588,17 +630,6 @@ export function InternalLinkPropPanel({
</div>
</div>
</InteractionPropPanel>
-
- <EditMarkdownLinkDialog
- open={editDialogOpen}
- href={href}
- text={linkText}
- pages={pages}
- folderPaths={folderPaths}
- loading={loading}
- onOpenChange={setEditDialogOpen}
- onSave={handleSave}
- />
</>
);
}
diff --git a/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx b/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx
index 1cdaba34a..217bd7815 100644
--- a/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx
+++ b/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx
@@ -39,7 +39,11 @@ import { type CreatePageSeed, createPageFromSeedAndUpdate } from '../../lib/crea
import { hashFromAssetPath } from '../../lib/doc-hash';
import { cn } from '../../lib/utils';
import { handleChipLinkClick, toInternalHashHref } from '../internal-link-helpers';
-import { type LinkPathSuggestion, LinkPathSuggestionInput } from '../link-path-suggestions';
+import {
+ type LinkPathSuggestion,
+ LinkPathSuggestionInput,
+ preventLinkPathSuggestionDialogDismiss,
+} from '../link-path-suggestions';
import { isSafeNavigationUrl } from '../safe-navigation-url';
import { CopyButton } from './LinkPropPanelCopy';
import { useHeadings } from './use-headings';
@@ -128,7 +132,13 @@ function EditWikiLinkDialog({
return (
<Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="sm:max-w-xl" data-ok-layer-spawned="">
+ <DialogContent
+ className="sm:max-w-xl"
+ data-ok-layer-spawned=""
+ onPointerDownOutside={preventLinkPathSuggestionDialogDismiss}
+ onFocusOutside={preventLinkPathSuggestionDialogDismiss}
+ onInteractOutside={preventLinkPathSuggestionDialogDismiss}
+ >
<DialogHeader>
<DialogTitle>
<Trans>Edit wiki link</Trans>
diff --git a/packages/app/src/editor/link-path-suggestions.dom.test.tsx b/packages/app/src/editor/link-path-suggestions.dom.test.tsx
index 9cca07ced..be03b02a8 100644
--- a/packages/app/src/editor/link-path-suggestions.dom.test.tsx
+++ b/packages/app/src/editor/link-path-suggestions.dom.test.tsx
@@ -1,11 +1,18 @@
import { afterEach, describe, expect, test } from 'bun:test';
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { useState } from 'react';
-import { type LinkPathSuggestion, LinkPathSuggestionInput } from './link-path-suggestions';
+import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
+import {
+ isLinkPathSuggestionPanelTarget,
+ type LinkPathSuggestion,
+ LinkPathSuggestionInput,
+ preventLinkPathSuggestionDialogDismiss,
+} from './link-path-suggestions';
const pages = new Set(['docs/install', 'guides/bun', 'guides/intro']);
const folderPaths = new Set(['docs', 'guides']);
const nativeScrollIntoView = HTMLElement.prototype.scrollIntoView;
+let pointerEventsStyle: HTMLStyleElement | null = null;
function Harness({
initialValue,
@@ -39,6 +46,8 @@ function Harness({
afterEach(() => {
cleanup();
+ pointerEventsStyle?.remove();
+ pointerEventsStyle = null;
if (nativeScrollIntoView) {
HTMLElement.prototype.scrollIntoView = nativeScrollIntoView;
} else {
@@ -47,6 +56,15 @@ afterEach(() => {
});
describe('LinkPathSuggestionInput', () => {
+ test('opens project path suggestions when empty input has focus', () => {
+ render(<Harness initialValue="" />);
+
+ fireEvent.focus(screen.getByRole('combobox', { name: 'Link target' }));
+
+ expect(screen.getByRole('listbox', { name: 'Path suggestions' })).toBeDefined();
+ expect(screen.getByRole('option', { name: '/docs/install Page' })).toBeDefined();
+ });
+
test('opens project path suggestions when slash input has focus', () => {
render(<Harness initialValue="/guides" />);
@@ -126,6 +144,42 @@ describe('LinkPathSuggestionInput', () => {
expect(touchMoveEvents).toBe(0);
});
+ test('keeps portaled suggestions interactive inside modal dialogs', () => {
+ pointerEventsStyle = document.createElement('style');
+ pointerEventsStyle.textContent = '.pointer-events-auto { pointer-events: auto; }';
+ document.head.append(pointerEventsStyle);
+
+ render(
+ <Dialog open>
+ <DialogContent aria-describedby={undefined}>
+ <DialogTitle>Edit markdown link</DialogTitle>
+ <Harness
+ initialValue="/"
+ harnessPages={new Set(Array.from({ length: 12 }, (_, index) => `docs/${index}`))}
+ harnessFolderPaths={new Set()}
+ />
+ </DialogContent>
+ </Dialog>,
+ );
+
+ fireEvent.focus(screen.getByRole('combobox', { name: 'Link target' }));
+
+ const listbox = screen.getByRole('listbox', { name: 'Path suggestions' });
+ expect(document.body.style.pointerEvents).toBe('none');
+ expect(listbox.parentElement).toBe(document.body);
+ expect(getComputedStyle(listbox).pointerEvents).toBe('auto');
+ expect(isLinkPathSuggestionPanelTarget(listbox)).toBe(true);
+
+ let prevented = false;
+ preventLinkPathSuggestionDialogDismiss({
+ target: listbox,
+ preventDefault: () => {
+ prevented = true;
+ },
+ });
+ expect(prevented).toBe(true);
+ });
+
test('Escape dismisses the suggestion panel', () => {
render(<Harness initialValue="/guides" />);
@@ -152,6 +206,20 @@ describe('LinkPathSuggestionInput', () => {
expect(screen.getByRole('listbox', { name: 'Path suggestions' })).toBeDefined();
});
+ test('Escape dismisses empty-input suggestions and typing reopens them', () => {
+ render(<Harness initialValue="" />);
+
+ const input = screen.getByRole('combobox', { name: 'Link target' });
+ fireEvent.focus(input);
+ expect(screen.getByRole('listbox', { name: 'Path suggestions' })).toBeDefined();
+
+ fireEvent.keyDown(input, { key: 'Escape' });
+ expect(screen.queryByRole('listbox', { name: 'Path suggestions' })).toBeNull();
+
+ fireEvent.change(input, { target: { value: '/' } });
+ expect(screen.getByRole('listbox', { name: 'Path suggestions' })).toBeDefined();
+ });
+
test('ArrowDown and ArrowUp update the active option', () => {
render(<Harness initialValue="/guides" />);
diff --git a/packages/app/src/editor/link-path-suggestions.tsx b/packages/app/src/editor/link-path-suggestions.tsx
index 5248e6658..60993a6b8 100644
--- a/packages/app/src/editor/link-path-suggestions.tsx
+++ b/packages/app/src/editor/link-path-suggestions.tsx
@@ -24,6 +24,21 @@ import {
export type { LinkPathSuggestion } from './link-path-suggestions-core';
+const LINK_PATH_SUGGESTION_PANEL_SELECTOR = '[data-ok-link-path-suggestion-panel]';
+
+export function isLinkPathSuggestionPanelTarget(target: EventTarget | null): boolean {
+ return target instanceof Element && target.closest(LINK_PATH_SUGGESTION_PANEL_SELECTOR) !== null;
+}
+
+export function preventLinkPathSuggestionDialogDismiss(event: {
+ target: EventTarget | null;
+ preventDefault: () => void;
+}) {
+ if (isLinkPathSuggestionPanelTarget(event.target)) {
+ event.preventDefault();
+ }
+}
+
function suggestionIcon(kind: LinkPathSuggestionKind) {
switch (kind) {
case 'page':
@@ -92,8 +107,10 @@ export function LinkPathSuggestionInput({
const panelRef = useRef<HTMLDivElement | null>(null);
const listId = useId();
+ const emptyTriggered = value.trim() === '';
+ const suggestionValue = emptyTriggered ? '/' : value;
const suggestions = buildLinkPathSuggestions({
- value,
+ value: suggestionValue,
pages,
folderPaths,
assetPaths,
@@ -103,11 +120,12 @@ export function LinkPathSuggestionInput({
.map((suggestion) => `${suggestion.kind}:${suggestion.path}`)
.join('\u0000');
const slashTriggered = isSlashPathSuggestionValue(value);
+ const suggestionTriggered = emptyTriggered || slashTriggered;
const showSuggestionOptions = suggestions.length > 0;
const showSuggestions =
- focused && !dismissed && slashTriggered && (showSuggestionOptions || loading);
+ focused && !dismissed && suggestionTriggered && (showSuggestionOptions || loading);
const showNoMatches =
- focused && !dismissed && slashTriggered && !loading && !showSuggestionOptions;
+ focused && !dismissed && suggestionTriggered && !loading && !showSuggestionOptions;
const showSuggestionPanel = showSuggestions || showNoMatches;
const activeIndex = Math.min(highlightedIndex, Math.max(suggestions.length - 1, 0));
const activeId = showSuggestionOptions ? `${listId}-option-${activeIndex}` : undefined;
@@ -233,7 +251,9 @@ export function LinkPathSuggestionInput({
id={listId}
role="listbox"
aria-label={t`Path suggestions`}
- className="fixed z-70 max-h-52 overflow-y-auto overscroll-y-contain rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md subtle-scrollbar"
+ data-ok-layer-spawned=""
+ data-ok-link-path-suggestion-panel=""
+ className="fixed z-70 max-h-52 overflow-y-auto overscroll-y-contain rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md subtle-scrollbar pointer-events-auto"
onWheel={(event) => {
event.stopPropagation();
}}
@@ -304,9 +324,7 @@ export function LinkPathSuggestionInput({
/>
{/* Manual portal + Floating UI keeps the listbox out of clipped dialog
bodies and avoids nested Radix Popover focus management in prop panels. */}
- {suggestionPanel && typeof document !== 'undefined'
- ? createPortal(suggestionPanel, document.body)
- : null}
+ {suggestionPanel && createPortal(suggestionPanel, document.body)}
</div>
);
}
diff --git a/packages/app/src/editor/slash-command/component-items.test.ts b/packages/app/src/editor/slash-command/component-items.test.ts
index e4e4379de..25bd0963d 100644
--- a/packages/app/src/editor/slash-command/component-items.test.ts
+++ b/packages/app/src/editor/slash-command/component-items.test.ts
@@ -193,11 +193,11 @@ describe('agent-surface ↔ slash-menu filter parity', () => {
});
describe('getInlineComponentItems — inline-atom slash entries', () => {
- test('returns Link-to-a-page, External Link, and Tag entries with unique names', () => {
+ test('returns Link and Tag entries with unique names', () => {
const items = getInlineComponentItems();
- expect(items.length).toBe(3);
+ expect(items.length).toBe(2);
const names = items.map((item) => item.name);
- expect(names).toEqual(['wikiLink', 'externalLink', 'component-Tag']);
+ expect(names).toEqual(['link', 'component-Tag']);
expect(new Set(names).size).toBe(names.length);
});
@@ -213,39 +213,16 @@ describe('getInlineComponentItems — inline-atom slash entries', () => {
expect(tag.aliases).toContain('#');
});
- test('Link-to-a-page entry re-triggers the [[ page picker by inserting the delimiter', () => {
- const wiki = getInlineComponentItems().find((item) => item.name === 'wikiLink');
- expect(wiki).toBeDefined();
- if (!wiki) return;
- expect(wiki.label).toBe('Link to a page');
- expect(wiki.category).toBe('insert');
- expect(wiki.aliases).toContain('wiki');
- expect(wiki.aliases).toContain('[[');
-
- let insertedContent: unknown;
- const editor = {
- chain: () => ({
- focus: () => ({
- insertContent: (content: unknown) => ({
- run: () => {
- insertedContent = content;
- },
- }),
- }),
- }),
- };
- wiki.command(editor as never);
- expect(insertedContent).toBe('[[');
- });
-
- test('External Link entry lands a placeholder link mark and no-ops auto-open without the identity plugin', () => {
- const external = getInlineComponentItems().find((item) => item.name === 'externalLink');
- expect(external).toBeDefined();
- if (!external) return;
- expect(external.label).toBe('External Link');
- expect(external.category).toBe('insert');
- expect(external.aliases).toContain('url');
- expect(external.aliases).toContain('external');
+ test('Link entry lands an empty placeholder link mark and no-ops auto-open without the identity plugin', () => {
+ const link = getInlineComponentItems().find((item) => item.name === 'link');
+ expect(link).toBeDefined();
+ if (!link) return;
+ expect(link.label).toBe('Link');
+ expect(link.category).toBe('insert');
+ expect(link.aliases).toContain('url');
+ expect(link.aliases).toContain('external');
+ expect(link.aliases).toContain('page');
+ expect(link.aliases).toContain('wiki');
let insertedContent: { type?: string; text?: string; marks?: unknown[] } | undefined;
let rafScheduled = false;
@@ -268,25 +245,23 @@ describe('getInlineComponentItems — inline-atom slash entries', () => {
}),
}),
};
- external.command(editor as never);
+ link.command(editor as never);
expect(insertedContent?.type).toBe('text');
expect(insertedContent?.text).toBe('link');
- expect(insertedContent?.marks).toEqual([{ type: 'link', attrs: { href: 'https://' } }]);
+ expect(insertedContent?.marks).toEqual([{ type: 'link', attrs: { href: '' } }]);
expect(rafScheduled).toBe(false);
} finally {
globalThis.requestAnimationFrame = originalRaf;
}
});
- test('External Link entry flags the inserted mark and schedules auto-open when mark-identity resolves it', () => {
- const external = getInlineComponentItems().find((item) => item.name === 'externalLink');
- expect(external).toBeDefined();
- if (!external) return;
+ test('Link entry flags the inserted mark and schedules auto-open when mark-identity resolves it', () => {
+ const link = getInlineComponentItems().find((item) => item.name === 'link');
+ expect(link).toBeDefined();
+ if (!link) return;
const getStateSpy = spyOn(markIdentityKey, 'getState').mockReturnValue({
- byId: new Map([
- ['m7', { id: 'm7', markType: 'link', from: 1, to: 5, attrs: { href: 'https://' } }],
- ]),
+ byId: new Map([['m7', { id: 'm7', markType: 'link', from: 1, to: 5, attrs: { href: '' } }]]),
counter: 7,
} as never);
@@ -306,7 +281,7 @@ describe('getInlineComponentItems — inline-atom slash entries', () => {
}),
}),
};
- external.command(editor as never);
+ link.command(editor as never);
expect(consumePendingLinkEdit('m7')).toBe(true);
expect(rafScheduled).toBe(true);
diff --git a/packages/app/src/editor/slash-command/component-items.tsx b/packages/app/src/editor/slash-command/component-items.tsx
index 70d9dbfa8..f30125b7c 100644
--- a/packages/app/src/editor/slash-command/component-items.tsx
+++ b/packages/app/src/editor/slash-command/component-items.tsx
@@ -463,16 +463,29 @@ function findLinkMarkIdAt(editor: Editor, pos: number): string | null {
export function getInlineComponentItems(): SlashCommandItem[] {
return [
{
- name: 'wikiLink',
- label: t`Link to a page`,
+ name: 'link',
+ label: t`Link`,
icon: Link2,
category: 'insert',
- aliases: ['wiki', 'wikilink', '[[', 'internal', 'page', 'backlink', 'cross-link'],
- description: 'Link to another page (`[[page]]`) — opens a page picker',
+ aliases: [
+ 'url',
+ 'href',
+ 'external',
+ 'web',
+ 'hyperlink',
+ 'wiki',
+ 'wikilink',
+ '[[',
+ 'internal',
+ 'page',
+ 'backlink',
+ 'cross-link',
+ ],
+ description: 'Link to a page or external URL',
preview: {
- description: t`Link to another page in this project.`,
+ description: t`Link to a page or external URL.`,
render: () => (
- <p className="text-sm leading-7">
+ <p className="leading-7 text-sm">
<Trans>
See{' '}
<span className="font-medium text-azure-blue underline underline-offset-2 dark:text-sky-blue">
@@ -483,32 +496,6 @@ export function getInlineComponentItems(): SlashCommandItem[] {
</p>
),
},
- command: (editor: Editor) => {
- editor.chain().focus().insertContent('[[').run();
- },
- },
- {
- name: 'externalLink',
- label: t`External Link`,
- icon: ExternalLink,
- category: 'insert',
- aliases: ['link', 'url', 'href', 'external', 'web', 'hyperlink'],
- description: 'Link to an external URL (`https://…`)',
- preview: {
- description: t`Link to an external URL.`,
- render: () => (
- <p className="text-sm leading-7">
- <Trans>
- Read the{' '}
- <span className="font-medium text-azure-blue underline underline-offset-2 dark:text-sky-blue">
- docs
- <span className="text-[0.85em] opacity-60"> ↗</span>
- </span>{' '}
- for details.
- </Trans>
- </p>
- ),
- },
command: (editor: Editor) => {
const insertPos = editor.state.selection.from;
editor
@@ -517,7 +504,7 @@ export function getInlineComponentItems(): SlashCommandItem[] {
.insertContent({
type: 'text',
text: 'link',
- marks: [{ type: 'link', attrs: { href: 'https://' } }],
+ marks: [{ type: 'link', attrs: { href: '' } }],
})
.run();
diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.json
index 3fdc9aadc..099b4b59c 100644
--- a/packages/app/src/locales/en/messages.json
+++ b/packages/app/src/locales/en/messages.json
@@ -211,6 +211,7 @@
"5QGTaA": ["Could not copy relative path"],
"5SwVv1": ["Not installed"],
"5Tk8Fb": ["Loading files"],
+ "5WDhAk": ["Link to a page or external URL."],
"5gr_ev": [
"Becomes the document's content when someone creates a doc from this template. Type <0>",
["dateToken"],
diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.po
index 40807d8a4..c197c11fe 100644
--- a/packages/app/src/locales/en/messages.po
+++ b/packages/app/src/locales/en/messages.po
@@ -2094,8 +2094,8 @@ msgid "External link"
msgstr "External link"
#: src/editor/slash-command/component-items.tsx
-msgid "External Link"
-msgstr "External Link"
+#~ msgid "External Link"
+#~ msgstr "External Link"
#: src/editor/extensions/WikiLinkPropPanel.tsx
msgid "External wiki link"
@@ -2902,6 +2902,7 @@ msgid "Light, dark, or follow the OS."
msgstr "Light, dark, or follow the OS."
#: src/editor/bubble-menu/LinkEditPopover.tsx
+#: src/editor/slash-command/component-items.tsx
msgid "Link"
msgstr "Link"
@@ -2914,16 +2915,20 @@ msgid "Link target"
msgstr "Link target"
#: src/editor/slash-command/component-items.tsx
-msgid "Link to a page"
-msgstr "Link to a page"
+#~ msgid "Link to a page"
+#~ msgstr "Link to a page"
+
+#: src/editor/slash-command/component-items.tsx
+msgid "Link to a page or external URL."
+msgstr "Link to a page or external URL."
#: src/editor/slash-command/component-items.tsx
-msgid "Link to an external URL."
-msgstr "Link to an external URL."
+#~ msgid "Link to an external URL."
+#~ msgstr "Link to an external URL."
#: src/editor/slash-command/component-items.tsx
-msgid "Link to another page in this project."
-msgstr "Link to another page in this project."
+#~ msgid "Link to another page in this project."
+#~ msgstr "Link to another page in this project."
#: src/editor/bubble-menu/LinkEditPopover.tsx
msgid "Link URL"
@@ -4348,8 +4353,8 @@ msgid "Re-authenticate with GitHub"
msgstr "Re-authenticate with GitHub"
#: src/editor/slash-command/component-items.tsx
-msgid "Read the <0>docs<1> ↗</1></0> for details."
-msgstr "Read the <0>docs<1> ↗</1></0> for details."
+#~ msgid "Read the <0>docs<1> ↗</1></0> for details."
+#~ msgstr "Read the <0>docs<1> ↗</1></0> for details."
#: src/editor/slash-command/component-items.tsx
msgid "Read-only copy of a MirrorSource block from another doc. Edit at the source — every Mirror reflects the change live."
diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.json
index f62487df1..933c68126 100644
--- a/packages/app/src/locales/pseudo/messages.json
+++ b/packages/app/src/locales/pseudo/messages.json
@@ -211,6 +211,7 @@
"5QGTaA": ["Ćōũĺď ńōţ ćōƥŷ ŕēĺàţĩvē ƥàţĥ"],
"5SwVv1": ["Ńōţ ĩńśţàĺĺēď"],
"5Tk8Fb": ["Ĺōàďĩńĝ ƒĩĺēś"],
+ "5WDhAk": ["Ĺĩńķ ţō à ƥàĝē ōŕ ēxţēŕńàĺ ŨŔĹ."],
"5gr_ev": [
"ßēćōḿēś ţĥē ďōćũḿēńţ'ś ćōńţēńţ ŵĥēń śōḿēōńē ćŕēàţēś à ďōć ƒŕōḿ ţĥĩś ţēḿƥĺàţē. Ţŷƥē <0>",
["dateToken"],
diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.po
index a00a1f47d..81e00e97a 100644
--- a/packages/app/src/locales/pseudo/messages.po
+++ b/packages/app/src/locales/pseudo/messages.po
@@ -2089,8 +2089,8 @@ msgid "External link"
msgstr ""
#: src/editor/slash-command/component-items.tsx
-msgid "External Link"
-msgstr ""
+#~ msgid "External Link"
+#~ msgstr ""
#: src/editor/extensions/WikiLinkPropPanel.tsx
msgid "External wiki link"
@@ -2897,6 +2897,7 @@ msgid "Light, dark, or follow the OS."
msgstr ""
#: src/editor/bubble-menu/LinkEditPopover.tsx
+#: src/editor/slash-command/component-items.tsx
msgid "Link"
msgstr ""
@@ -2909,16 +2910,20 @@ msgid "Link target"
msgstr ""
#: src/editor/slash-command/component-items.tsx
-msgid "Link to a page"
-msgstr ""
+#~ msgid "Link to a page"
+#~ msgstr ""
#: src/editor/slash-command/component-items.tsx
-msgid "Link to an external URL."
+msgid "Link to a page or external URL."
msgstr ""
#: src/editor/slash-command/component-items.tsx
-msgid "Link to another page in this project."
-msgstr ""
+#~ msgid "Link to an external URL."
+#~ msgstr ""
+
+#: src/editor/slash-command/component-items.tsx
+#~ msgid "Link to another page in this project."
+#~ msgstr ""
#: src/editor/bubble-menu/LinkEditPopover.tsx
msgid "Link URL"
@@ -4343,8 +4348,8 @@ msgid "Re-authenticate with GitHub"
msgstr ""
#: src/editor/slash-command/component-items.tsx
-msgid "Read the <0>docs<1> ↗</1></0> for details."
-msgstr ""
+#~ msgid "Read the <0>docs<1> ↗</1></0> for details."
+#~ msgstr ""
#: src/editor/slash-command/component-items.tsx
msgid "Read-only copy of a MirrorSource block from another doc. Edit at the source — every Mirror reflects the change live."
diff --git a/packages/app/tests/stress/ux-interactions.e2e.ts b/packages/app/tests/stress/ux-interactions.e2e.ts
index da7e02a7a..a7bca4e0b 100644
--- a/packages/app/tests/stress/ux-interactions.e2e.ts
+++ b/packages/app/tests/stress/ux-interactions.e2e.ts
@@ -263,10 +263,17 @@ test('markdown link edit dialog preserves page mode while clearing and updates t
page,
api,
}) => {
- const docName = await openFreshDoc(api, page, 'link-edit');
+ const docName = uniqueDocName('link-edit');
+ const suggestionTarget = uniqueDocName('link-edit-target');
const doc = '[Beta page](beta.md)';
- await api.replaceDoc(docName, doc);
+ await api.seedDocs([
+ { name: docName, markdown: doc },
+ { name: suggestionTarget, markdown: '# Target\n' },
+ ]);
+ await page.goto(`/#/${docName}`);
+ await waitForProvider(page);
+ await page.waitForSelector('.ProseMirror');
await page.waitForFunction(
() =>
@@ -299,16 +306,22 @@ test('markdown link edit dialog preserves page mode while clearing and updates t
await expect(pageLabel).toBeVisible();
await expect(sectionLabel).toBeVisible();
- await targetInput.fill('sidebar-folder/nested-doc');
+ await targetInput.fill(`/${suggestionTarget}`);
+ const suggestion = page.getByRole('option', { name: `/${suggestionTarget} Page` });
+ await expect(suggestion).toBeVisible();
+ await suggestion.click();
+ await expect(page.getByRole('dialog', { name: 'Edit markdown link' })).toBeVisible();
+ await expect(targetInput).toHaveValue(suggestionTarget);
+
await page.getByRole('button', { name: 'Save' }).click();
await page.waitForFunction(
- () =>
+ (target) =>
window.__activeProvider?.document
?.getText('source')
?.toString()
- ?.includes('[Beta page](./sidebar-folder/nested-doc.md)'),
- null,
+ ?.includes(`[Beta page](./${target}.md)`),
+ suggestionTarget,
{ timeout: 10_000 },
);
});