Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down