Skip to content
Merged
Changes from 1 commit
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
Next Next commit
fix(frontend): Improve paste handler for table cells
This replaces the broken approach from #3906.

* Only regard paste handler if pasting to a table cell (Fixes: #4443)
* Add all (marked) text nodes with newlines in between
* Only add a newline for non-text nodes to prevent newlines in between
  text with changing marks.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- authored and backportbot-nextcloud[bot] committed Jul 10, 2023
commit 93a2eb48455a822eb21a07566d6563f042645128
36 changes: 18 additions & 18 deletions src/nodes/Table/TableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ export default TableCell.extend({
return [
new Plugin({
props: {
// Special-treat empty lines in pasted content to prevent jumping out of cell
// Only paste (marked) text into table cells to prevent jumping out of cell
handlePaste: (view, event, slice) => {
if (slice.content.childCount > 1) {
const state = view.state
const childCount = slice.content.childCount
const childNodes = []
for (let i = 0; i < childCount; i++) {
if (i === 0) {
childNodes.push(state.schema.text('\n'))
}

// Ignore empty children (i.e. empty lines)
if (!slice.content.child(i).firstChild) {
continue
}
if (!this.editor.isActive(this.type.name)) {
return false
}

childNodes.push(state.schema.text(slice.content.child(i).textContent, slice.content.child(i).firstChild.marks))
const { state } = view
const childNodes = []
let newLineAdded = false
slice.content.descendants((node, pos) => {
if (node.isText) {
childNodes.push(state.schema.text(node.textContent, node.marks))
newLineAdded = false
} else if (!newLineAdded) {
childNodes.push(state.schema.text('\n'))
newLineAdded = true
}
const newNode = view.state.schema.node('paragraph', [], childNodes)
slice.content = Fragment.empty.addToStart(newNode)
}
})

const newNode = state.schema.node('paragraph', [], childNodes)
slice.content = Fragment.empty.addToStart(newNode)
},
},
}),
Expand Down