mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 05:07:43 +02:00
fix: paste as plain text when in code block (#10058)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user