Fix Newline handling in Web's Composer (#6658)
This commit is contained in:
@@ -11,6 +11,7 @@ import {Paragraph} from '@tiptap/extension-paragraph'
|
|||||||
import {Placeholder} from '@tiptap/extension-placeholder'
|
import {Placeholder} from '@tiptap/extension-placeholder'
|
||||||
import {Text as TiptapText} from '@tiptap/extension-text'
|
import {Text as TiptapText} from '@tiptap/extension-text'
|
||||||
import {generateJSON} from '@tiptap/html'
|
import {generateJSON} from '@tiptap/html'
|
||||||
|
import {Fragment, Node, Slice} from '@tiptap/pm/model'
|
||||||
import {EditorContent, JSONContent, useEditor} from '@tiptap/react'
|
import {EditorContent, JSONContent, useEditor} from '@tiptap/react'
|
||||||
|
|
||||||
import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
||||||
@@ -166,6 +167,11 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
|||||||
const editor = useEditor(
|
const editor = useEditor(
|
||||||
{
|
{
|
||||||
extensions,
|
extensions,
|
||||||
|
coreExtensionOptions: {
|
||||||
|
clipboardTextSerializer: {
|
||||||
|
blockSeparator: '\n',
|
||||||
|
},
|
||||||
|
},
|
||||||
onFocus() {
|
onFocus() {
|
||||||
onFocus?.()
|
onFocus?.()
|
||||||
},
|
},
|
||||||
@@ -173,6 +179,20 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
|||||||
attributes: {
|
attributes: {
|
||||||
class: modeClass,
|
class: modeClass,
|
||||||
},
|
},
|
||||||
|
clipboardTextParser: (text, context) => {
|
||||||
|
const blocks = text.split(/(?:\r\n?|\n)/)
|
||||||
|
const nodes: Node[] = blocks.map(line => {
|
||||||
|
return Node.fromJSON(
|
||||||
|
context.doc.type.schema,
|
||||||
|
line.length > 0
|
||||||
|
? {type: 'paragraph', content: [{type: 'text', text: line}]}
|
||||||
|
: {type: 'paragraph', content: []},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const fragment = Fragment.fromArray(nodes)
|
||||||
|
return Slice.maxOpen(fragment)
|
||||||
|
},
|
||||||
handlePaste: (view, event) => {
|
handlePaste: (view, event) => {
|
||||||
const clipboardData = event.clipboardData
|
const clipboardData = event.clipboardData
|
||||||
let preventDefault = false
|
let preventDefault = false
|
||||||
|
|||||||
Reference in New Issue
Block a user