Skip to content

Commit

Permalink
Fix Newline handling in Web's Composer (#6658)
Browse files Browse the repository at this point in the history
  • Loading branch information
HorusGoul authored Nov 23, 2024
1 parent d29599f commit 4dd62e2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/view/com/composer/text-input/TextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Paragraph} from '@tiptap/extension-paragraph'
import {Placeholder} from '@tiptap/extension-placeholder'
import {Text as TiptapText} from '@tiptap/extension-text'
import {generateJSON} from '@tiptap/html'
import {Fragment, Node, Slice} from '@tiptap/pm/model'
import {EditorContent, JSONContent, useEditor} from '@tiptap/react'

import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
Expand Down Expand Up @@ -166,13 +167,32 @@ export const TextInput = React.forwardRef(function TextInputImpl(
const editor = useEditor(
{
extensions,
coreExtensionOptions: {
clipboardTextSerializer: {
blockSeparator: '\n',
},
},
onFocus() {
onFocus?.()
},
editorProps: {
attributes: {
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) => {
const clipboardData = event.clipboardData
let preventDefault = false
Expand Down

0 comments on commit 4dd62e2

Please sign in to comment.