Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit be0d759

Browse files
authored
Merge pull request #231 from ckeditor/i/6062
Fix: Fixed a bug with spellchecking or pasting via the context menu into a table cell crashing the editor. Closes ckeditor/ckeditor5#6062
2 parents ec22240 + 9bcddfe commit be0d759

File tree

7 files changed

+75
-9
lines changed

7 files changed

+75
-9
lines changed

src/converters/downcast.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ function createViewTableCellElement( tableWalkerValue, tableAttributes, insertPo
397397
conversionApi.consumable.consume( innerParagraph, 'insert' );
398398

399399
if ( options.asWidget ) {
400-
const fakeParagraph = conversionApi.writer.createContainerElement( 'span' );
400+
// Use display:inline-block to force Chrome/Safari to limit text mutations to this element.
401+
// See #6062.
402+
const fakeParagraph = conversionApi.writer.createContainerElement( 'span', { style: 'display:inline-block' } );
401403

402404
conversionApi.mapper.bindElements( innerParagraph, fakeParagraph );
403405
conversionApi.writer.insert( paragraphInsertPosition, fakeParagraph );

tests/_utils/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ function makeRows( tableData, options ) {
368368
}
369369

370370
if ( !( contents.replace( '[', '' ).replace( ']', '' ).startsWith( '<' ) ) && enforceWrapping ) {
371-
contents = `<${ wrappingElement }>${ contents }</${ wrappingElement }>`;
371+
contents =
372+
`<${ wrappingElement == 'span' ? 'span style="display:inline-block"' : wrappingElement }>` +
373+
contents +
374+
`</${ wrappingElement }>`;
372375
}
373376

374377
const formattedAttributes = formatAttributes( attributes );

tests/converters/downcast.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ function paragraphInTableCell() {
2626

2727
if ( viewElement && viewElement.name === 'span' ) {
2828
conversionApi.mapper.unbindModelElement( tableCell );
29+
30+
conversionApi.writer.removeStyle( 'display', viewElement );
2931
conversionApi.writer.rename( 'p', viewElement );
32+
3033
conversionApi.mapper.bindElements( child, viewElement );
3134
}
3235
}
@@ -339,7 +342,9 @@ describe( 'downcast converters', () => {
339342
'<table>' +
340343
'<tbody>' +
341344
'<tr>' +
342-
'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"><span></span></td>' +
345+
'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
346+
'<span style="display:inline-block"></span>' +
347+
'</td>' +
343348
'</tr>' +
344349
'</tbody>' +
345350
'</table>' +
@@ -572,7 +577,7 @@ describe( 'downcast converters', () => {
572577
'<tbody>' +
573578
'<tr>' +
574579
'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
575-
'<span>00</span>' +
580+
'<span style="display:inline-block">00</span>' +
576581
'</td>' +
577582
'</tr>' +
578583
'<tr>' +
@@ -718,7 +723,7 @@ describe( 'downcast converters', () => {
718723
'<tbody>' +
719724
'<tr>' +
720725
'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
721-
'<span>00</span>' +
726+
'<span style="display:inline-block">00</span>' +
722727
'</td>' +
723728
'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"></td>' +
724729
'</tr>' +
@@ -895,7 +900,7 @@ describe( 'downcast converters', () => {
895900
'<thead>' +
896901
'<tr>' +
897902
'<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
898-
'<span>00</span>' +
903+
'<span style="display:inline-block">00</span>' +
899904
'</th>' +
900905
'</tr>' +
901906
'</thead>' +
@@ -1109,7 +1114,7 @@ describe( 'downcast converters', () => {
11091114
'<tbody>' +
11101115
'<tr>' +
11111116
'<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
1112-
'<span>00</span>' +
1117+
'<span style="display:inline-block">00</span>' +
11131118
'</th>' +
11141119
'</tr>' +
11151120
'</tbody>' +

tests/converters/table-cell-refresh-post-fixer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe( 'Table cell refresh post-fixer', () => {
169169
} );
170170

171171
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
172-
[ '<span>00</span>' ]
172+
[ '<span style="display:inline-block">00</span>' ]
173173
], { asWidget: true } ) );
174174
sinon.assert.calledOnce( refreshItemSpy );
175175
} );
@@ -279,7 +279,7 @@ describe( 'Table cell refresh post-fixer', () => {
279279
} );
280280

281281
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
282-
[ '<span>00</span>' ]
282+
[ '<span style="display:inline-block">00</span>' ]
283283
], { asWidget: true } ) );
284284
sinon.assert.calledOnce( refreshItemSpy );
285285
} );

tests/manual/tickets/6062.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div id="editor">
2+
<figure class="table">
3+
<table>
4+
<thead>
5+
<tr>
6+
<th>at the end:</th>
7+
<th>at the beginning:</th>
8+
<th>entire cell:</th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
<tr>
13+
<td>Hello, commter</td>
14+
<td>Commter, hello!</td>
15+
<td>Commter</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
</figure>
20+
</div>

tests/manual/tickets/6062.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4+
*/
5+
6+
/* globals console, window, document */
7+
8+
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
9+
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
10+
11+
ClassicEditor
12+
.create( document.querySelector( '#editor' ), {
13+
plugins: [ ArticlePluginSet ],
14+
toolbar: [
15+
'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
16+
],
17+
table: {
18+
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
19+
tableToolbar: [ 'bold', 'italic' ]
20+
}
21+
} )
22+
.then( editor => {
23+
window.editor = editor;
24+
} )
25+
.catch( err => {
26+
console.error( err.stack );
27+
} );

tests/manual/tickets/6062.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ticket test: [#6062](https://github.com/ckeditor/ckeditor5/issues/6062)
2+
3+
1. Right-click the misspelled word.
4+
2. Choose one of the corrections.
5+
6+
Expected:
7+
8+
* No errors.
9+
* The misspelled word should be correctly replaced. E.g., you shouldn't see a new paragraph being created.

0 commit comments

Comments
 (0)