From e5166c3ab7497d04e6a4ce01a139747c5c28f8a1 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Thu, 9 Oct 2025 14:05:36 +0700 Subject: [PATCH] fix: paste as plain text when in code block Signed-off-by: Alexander Onnikov --- .../src/components/extension/shortcuts/smartPaste.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/text-editor-resources/src/components/extension/shortcuts/smartPaste.ts b/plugins/text-editor-resources/src/components/extension/shortcuts/smartPaste.ts index b0aecd4a2f6..64f03aa1093 100644 --- a/plugins/text-editor-resources/src/components/extension/shortcuts/smartPaste.ts +++ b/plugins/text-editor-resources/src/components/extension/shortcuts/smartPaste.ts @@ -18,6 +18,7 @@ import { markdownToMarkup } from '@hcengineering/text-markdown' import { Extension } from '@tiptap/core' import { Node, type Schema } from '@tiptap/pm/model' import { Plugin } from '@tiptap/pm/state' +import { CodeBlockHighlighExtension } from '../codeSnippets/codeblock' export const SmartPasteExtension = Extension.create({ name: 'transformPastedContent', @@ -35,6 +36,17 @@ function PasteTextAsMarkdownPlugin (): Plugin { if (clipboardData === null) return false const pastedText = clipboardData.getData('text/plain') + + // check if we are in code block + const { $from } = view.state.selection + for (let d = $from.depth; d > 0; d--) { + const node = $from.node(d) + if (node.type.name === CodeBlockHighlighExtension.name) { + // paste as plain text in code blocks + return false + } + } + const isPlainPaste = clipboardData.types.length === 1 && clipboardData.types[0] === 'text/plain' if (!isPlainPaste) return false