Skip to content

Commit

Permalink
fix: paste multiple line to table issue
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Mar 6, 2023
1 parent 621c744 commit 2a54b60
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/nodes/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TableCell from './TableCell.js'
import TableHeader from './TableHeader.js'
import TableHeadRow from './TableHeadRow.js'
import TableRow from './TableRow.js'
import { TextSelection } from '@tiptap/pm/state'
import { Plugin, TextSelection } from '@tiptap/pm/state'
import {
addRowAfter,
addRowBefore,
Expand All @@ -14,6 +14,8 @@ import {
selectedRect,
selectionCell,
} from '@tiptap/pm/tables'
// eslint-disable-next-line n/no-extraneous-import
import { Fragment } from 'prosemirror-model'

/**
*
Expand Down Expand Up @@ -207,4 +209,25 @@ export default Table.extend({
}
},

addProseMirrorPlugins() {
return [
new Plugin({
props: {
handlePaste: (view, event, slice) => {
if (slice.content.childCount > 1) {
const firstNode = slice.content.firstChild
let newTextContent = firstNode.textContent

for (let i = 1; i < slice.content.childCount; i++) {
newTextContent += '\n' + slice.content.child(i).textContent
}

slice.content = Fragment.empty.addToStart(view.state.schema.text(newTextContent, firstNode.marks))
}
},
},
}),
]
},

})

0 comments on commit 2a54b60

Please sign in to comment.