Files
outline/app/scenes/Document/components/Comments/CommentEditor.tsx
T
Tom MoorandClaude Opus 5 9181bf61b6 Add [[ trigger for mentioning or creating a document (#13402)
* feat: Add [[ trigger for mentioning or creating a document

Opens a suggestions menu filtered to documents, backed by a title search,
with options to create a new or nested document from the search term.

Generalizes the suggestion machinery to support multi-character triggers,
and extracts the mention menu item builders into app/editor/menus/mention.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: Trim the mention search term

Spaces are allowed in the search term, so a whitespace-only query rendered
create-document items with an empty title and issued a title search that the
server rejects.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: Close suggestion menus on a space directly after the trigger

Spaces remain allowed within a search term, they are only rejected as its
first character.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: Return models from fetchNamedPage

The raw API payload was returned rather than the models added to the store,
so callers that render the result are missing computed properties.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* refactor: Render the document menu from the store

Matches the mention menu and paginated lists, where the request populates the
store and the list is rendered from observables.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat: Order people above documents in the mention menu

Uses a mention specific section so the command bar, where the section holds
user management actions, is unaffected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: Hide create document options without a create handler

Editors that do not pass onCreateLink, such as comments, inserted a mention
pointing at a document that was never created.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 07:57:13 -04:00

55 lines
1.8 KiB
TypeScript

import { observer } from "mobx-react";
import * as React from "react";
import { basicExtensions, withComments } from "@shared/editor/nodes";
import CodeBlock from "@shared/editor/nodes/CodeBlock";
import CodeFence from "@shared/editor/nodes/CodeFence";
import HardBreak from "@shared/editor/nodes/HardBreak";
import type { Props as EditorProps } from "~/components/Editor";
import Editor from "~/components/Editor";
import type { Editor as SharedEditor } from "~/editor";
import ClipboardTextSerializer from "~/editor/extensions/ClipboardTextSerializer";
import DocumentMenuExtension from "~/editor/extensions/DocumentMenu";
import EmojiMenuExtension from "~/editor/extensions/EmojiMenu";
import Keys from "~/editor/extensions/Keys";
import MentionMenuExtension from "~/editor/extensions/MentionMenu";
import PasteHandler from "~/editor/extensions/PasteHandler";
import PreventTab from "~/editor/extensions/PreventTab";
import SmartText from "~/editor/extensions/SmartText";
import UpArrowAtStart from "~/editor/extensions/UpArrowAtStart";
import useCurrentUser from "~/hooks/useCurrentUser";
const extensions = [
...withComments(basicExtensions),
CodeBlock,
CodeFence,
HardBreak,
SmartText,
PasteHandler,
ClipboardTextSerializer,
EmojiMenuExtension,
MentionMenuExtension,
DocumentMenuExtension,
UpArrowAtStart,
// Order these default key handlers last
PreventTab,
Keys,
];
type CommentEditorProps = EditorProps & {
/** Callback when user presses up arrow at the start of the editor */
onUpArrowAtStart?: () => void;
};
const CommentEditor = (
props: CommentEditorProps,
ref: React.RefObject<SharedEditor>
) => {
const user = useCurrentUser({ rejectOnEmpty: false });
return (
<Editor extensions={extensions} userId={user?.id} {...props} ref={ref} />
);
};
export default observer(React.forwardRef(CommentEditor));