Skip to content

Commit c637680

Browse files
authored
Merge pull request #4265 from nextcloud/backport/3906/stable26
[stable26] fix: paste multiple line to table issue
2 parents bc75a56 + b3ebd44 commit c637680

15 files changed

+70
-18
lines changed

cypress/e2e/nodes/Table.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ describe('table plugin', () => {
119119
.should('have.length', 3)
120120
.each(td => cy.wrap(td).should('have.css', 'text-align', 'center'))
121121
})
122+
123+
it('Creates table and add multilines', function() {
124+
const multilinesContent = 'Line 1\nLine 2\nLine 3'
125+
126+
cy.getActionEntry('table').click()
127+
cy.getContent()
128+
.find('table:nth-of-type(1) tr:nth-child(2) td:nth-child(1)')
129+
.click()
130+
131+
cy.getContent()
132+
.type(multilinesContent)
133+
134+
cy.getContent()
135+
.find('table:nth-of-type(1) tr:nth-child(2) td:nth-child(1) .content')
136+
.then(($el) => {
137+
expect($el.get(0).innerHTML).to.equal(multilinesContent.replace(/\n/g, '<br>'))
138+
})
139+
})
122140
})
123141

124142
describe('Table extension integrated in the editor', () => {

cypress/e2e/workspace.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ describe('Workspace', function() {
298298
checkContent()
299299
})
300300
})
301+
301302
})
302303

303304
const openSidebar = filename => {

js/editor.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/editor.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-editors.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-editors.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-files.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-files.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-public.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-public.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-text.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-text.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-viewer.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-viewer.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes/Table/TableCell.js

+33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { TableCell } from '@tiptap/extension-table-cell'
2+
import { Plugin } from '@tiptap/pm/state'
3+
import { Fragment } from '@tiptap/pm/model'
24

35
export default TableCell.extend({
46
content: 'inline*',
@@ -30,4 +32,35 @@ export default TableCell.extend({
3032
},
3133
}
3234
},
35+
36+
addProseMirrorPlugins() {
37+
return [
38+
new Plugin({
39+
props: {
40+
// Special-treat empty lines in pasted content to prevent jumping out of cell
41+
handlePaste: (view, event, slice) => {
42+
if (slice.content.childCount > 1) {
43+
const state = view.state
44+
const childCount = slice.content.childCount
45+
const childNodes = []
46+
for (let i = 0; i < childCount; i++) {
47+
if (i === 0) {
48+
childNodes.push(state.schema.text('\n'))
49+
}
50+
51+
// Ignore empty children (i.e. empty lines)
52+
if (!slice.content.child(i).firstChild) {
53+
continue
54+
}
55+
56+
childNodes.push(state.schema.text(slice.content.child(i).textContent, slice.content.child(i).firstChild.marks))
57+
}
58+
const newNode = view.state.schema.node('paragraph', [], childNodes)
59+
slice.content = Fragment.empty.addToStart(newNode)
60+
}
61+
},
62+
},
63+
}),
64+
]
65+
},
3366
})

0 commit comments

Comments
 (0)