Skip to content

Commit

Permalink
Merge pull request #4452 from nextcloud/fix/paste_formatting
Browse files Browse the repository at this point in the history
fix(frontend): Improve paste handler for table cells
  • Loading branch information
mejo- authored Jul 10, 2023
2 parents 004ab25 + 9c72f13 commit 22f98c8
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

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

0 comments on commit 22f98c8

Please sign in to comment.