diff --git a/app/editor/components/PasteMenu.tsx b/app/editor/components/PasteMenu.tsx index 114834f3b9..117a71799f 100644 --- a/app/editor/components/PasteMenu.tsx +++ b/app/editor/components/PasteMenu.tsx @@ -2,9 +2,11 @@ import { observer } from "mobx-react"; import { EmailIcon, LinkIcon } from "outline-icons"; import React from "react"; import { useTranslation } from "react-i18next"; +import { v4 } from "uuid"; import { EmbedDescriptor } from "@shared/editor/embeds"; import { MenuItem } from "@shared/editor/types"; import Integration from "~/models/Integration"; +import useCurrentUser from "~/hooks/useCurrentUser"; import useStores from "~/hooks/useStores"; import SuggestionsMenu, { Props as SuggestionsMenuProps, @@ -22,6 +24,7 @@ type Props = Omit< export const PasteMenu = observer(({ pastedText, embeds, ...props }: Props) => { const { t } = useTranslation(); const { integrations } = useStores(); + const user = useCurrentUser(); const url = pastedText ? new URL(pastedText) : undefined; @@ -61,13 +64,20 @@ export const PasteMenu = observer(({ pastedText, embeds, ...props }: Props) => { name: "mention", title: t("Mention"), icon: , - attrs: { type: mentionType }, + attrs: { + id: v4(), + type: mentionType, + label: pastedText, + href: pastedText, + modelId: v4(), + actorId: user.id, + }, appendSpace: true, }); } return menuItems; - }, [embed, t, mentionType]); + }, [t, embed, mentionType, pastedText, user]); return ( { filterable={false} renderMenuItem={(item, _index, options) => ( { - props.onSelect?.(item); - }} + onClick={options.onClick} selected={options.selected} title={item.title} icon={item.icon} diff --git a/app/editor/components/SuggestionsMenu.tsx b/app/editor/components/SuggestionsMenu.tsx index 23fc470a42..7ce101c1aa 100644 --- a/app/editor/components/SuggestionsMenu.tsx +++ b/app/editor/components/SuggestionsMenu.tsx @@ -12,7 +12,6 @@ import filterExcessSeparators from "@shared/editor/lib/filterExcessSeparators"; import { findParentNode } from "@shared/editor/queries/findParentNode"; import { MenuItem } from "@shared/editor/types"; import { depths, s } from "@shared/styles"; -import { MentionType } from "@shared/types"; import { getEventFiles } from "@shared/utils/files"; import { AttachmentValidation } from "@shared/validations"; import Header from "~/components/ContextMenu/Header"; @@ -234,11 +233,7 @@ function SuggestionsMenu(props: Props) { const attrs = typeof item.attrs === "function" ? item.attrs(view.state) : item.attrs; - const skipMention = - attrs?.type === MentionType.Issue || - attrs?.type === MentionType.PullRequest; // Mention node creation will be handled by PasteHandler. - - if (item.name === "noop" || (item.name === "mention" && skipMention)) { + if (item.name === "noop") { // Do nothing } else if (command) { command(attrs); diff --git a/app/editor/extensions/PasteHandler.tsx b/app/editor/extensions/PasteHandler.tsx index 4e449b75df..79504fc05c 100644 --- a/app/editor/extensions/PasteHandler.tsx +++ b/app/editor/extensions/PasteHandler.tsx @@ -415,26 +415,19 @@ export default class PasteHandler extends Extension { }); }; - private insertMention = (attrs: Record) => { + private insertMention = () => { const { view } = this.editor; const { state } = view; const result = this.findPlaceholder(state, this.state.pastedText); + // Remove just the placeholder here. + // Mention node will be created by SuggestionsMenu. if (result) { const tr = state.tr.deleteRange(result[0], result[1]); view.dispatch( tr.setSelection(TextSelection.near(tr.doc.resolve(result[0]))) ); } - - this.editor.commands.mention({ - id: v4(), - type: attrs.type as MentionType, - label: this.state.pastedText, - href: this.state.pastedText, - modelId: v4(), - actorId: stores.auth.currentUserId, - }); }; private removePlaceholder = () => { @@ -474,7 +467,7 @@ export default class PasteHandler extends Extension { } case "mention": { this.hidePasteMenu(); - this.insertMention(item.attrs as Record); + this.insertMention(); break; } default: