From 6d0270ae372b0d08ef2d83bb036144c4b18cc52f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 9 Jan 2025 09:18:10 -0500 Subject: [PATCH] Add paste handling --- app/editor/extensions/PasteHandler.ts | 33 ++++++++++++++++++++------- shared/editor/components/Styles.ts | 3 +-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/editor/extensions/PasteHandler.ts b/app/editor/extensions/PasteHandler.ts index a16f038974..218597f250 100644 --- a/app/editor/extensions/PasteHandler.ts +++ b/app/editor/extensions/PasteHandler.ts @@ -1,13 +1,14 @@ import { toggleMark } from "prosemirror-commands"; import { Slice } from "prosemirror-model"; import { Plugin } from "prosemirror-state"; +import { v4 } from "uuid"; import { LANGUAGES } from "@shared/editor/extensions/Prism"; import Extension from "@shared/editor/lib/Extension"; import isMarkdown from "@shared/editor/lib/isMarkdown"; import normalizePastedMarkdown from "@shared/editor/lib/markdown/normalize"; import { isInCode } from "@shared/editor/queries/isInCode"; import { isInList } from "@shared/editor/queries/isInList"; -import { IconType } from "@shared/types"; +import { IconType, MentionType } from "@shared/types"; import { determineIconType } from "@shared/utils/icon"; import parseDocumentSlug from "@shared/utils/parseDocumentSlug"; import { isDocumentUrl, isUrl } from "@shared/utils/urls"; @@ -185,15 +186,31 @@ export default class PasteHandler extends Extension { return; } if (document) { - const { hash } = new URL(text); + if (state.schema.nodes.mention) { + view.dispatch( + view.state.tr.replaceWith( + state.selection.from, + state.selection.to, + state.schema.nodes.mention.create({ + type: MentionType.Document, + modelId: document.id, + label: document.titleWithDefault, + id: v4(), + }) + ) + ); + } else { + const { hash } = new URL(text); + const hasEmoji = + determineIconType(document.icon) === + IconType.Emoji; - const hasEmoji = - determineIconType(document.icon) === IconType.Emoji; + const title = `${ + hasEmoji ? document.icon + " " : "" + }${document.titleWithDefault}`; - const title = `${ - hasEmoji ? document.icon + " " : "" - }${document.titleWithDefault}`; - insertLink(`${document.path}${hash}`, title); + insertLink(`${document.path}${hash}`, title); + } } }) .catch(() => { diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index f46826f8d6..1e95e9cded 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -296,7 +296,7 @@ width: 100%; font-weight: 500; font-size: 0.9em; cursor: default; - text-decoration: none; + text-decoration: none !important; display: inline-flex; align-items: center; @@ -304,7 +304,6 @@ width: 100%; vertical-align: bottom; &:hover { - text-decoration: none; cursor: default; }