Skip to content

Commit 337162d

Browse files
authored
Table format: support insert of multiline text to cell (T1086552) (#47)
1 parent a97646b commit 337162d

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

.github/workflows/functional-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Use Node.js
1717
uses: actions/setup-node@v2
1818
with:
19-
node-version: 'lts/*'
19+
node-version: '15'
2020
- run: sudo apt-get install xvfb
2121
- run: npm ci
2222
- run: npm run build

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Use Node.js
2222
uses: actions/setup-node@v2
2323
with:
24-
node-version: 'lts/*'
24+
node-version: '15'
2525
- run: sudo apt-get install xvfb
2626
- run: npm ci
2727
- run: npm run build

formats/table/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class CellLine extends Block {
5353
}
5454

5555
format(name, value) {
56+
const isCellLine = name === 'tableCellLine';
57+
if (isCellLine && value === null) {
58+
value = this.formats().tableCellLine;
59+
}
60+
5661
const isCell = CELL_IDENTITY_KEYS.indexOf(name) > -1;
5762
if (isCell || TABLE_FORMATS[name] || CELL_FORMATS[name]) {
5863
const attrName = `data-${isCell ? 'table-' : ''}${name.toLowerCase()}`;

test/unit/modules/table_main.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,26 @@ describe('Table Module', function() {
751751
});
752752

753753
it('insertText before', function() {
754-
this.quill.updateContents(new Delta().insert('\n'));
754+
const tableHTML = `
755+
<br>
756+
<table>
757+
<tbody>
758+
<tr><td>a1</td><td>a2</td><td>a3</td></tr>
759+
<tr><td>b1</td><td>b2</td><td>b3</td></tr>
760+
</tbody>
761+
</table>
762+
`;
763+
this.quill = this.initialize(Quill, tableHTML, this.container, {
764+
modules: {
765+
table: true,
766+
},
767+
});
768+
769+
this.quill.updateContents(new Delta().insert('\nBefore Line\n'));
755770
expect(this.quill.root).toEqualHTML(
756771
`
772+
<p><br></p>
773+
<p>Before Line</p>
757774
<p><br></p>
758775
<table>
759776
<tbody>
@@ -774,6 +791,35 @@ describe('Table Module', function() {
774791
);
775792
});
776793

794+
it('insert multiline text to cell (T1086552)', function() {
795+
this.quill.updateContents(
796+
new Delta().retain(8).insert('\nLine 1\nLine 2'),
797+
);
798+
expect(this.quill.root).toEqualHTML(
799+
`
800+
<table>
801+
<tbody>
802+
<tr>
803+
<td><p>a1</p></td>
804+
<td><p>a2</p></td>
805+
<td>
806+
<p>a3</p>
807+
<p>Line 1</p>
808+
<p>Line 2</p>
809+
</td>
810+
</tr>
811+
<tr>
812+
<td><p>b1</p></td>
813+
<td><p>b2</p></td>
814+
<td><p>b3</p></td>
815+
</tr>
816+
</tbody>
817+
</table>
818+
`,
819+
true,
820+
);
821+
});
822+
777823
it('insertText after', function() {
778824
this.quill.updateContents(new Delta().retain(18).insert('\n'));
779825
expect(this.quill.root).toEqualHTML(

0 commit comments

Comments
 (0)