Skip to content

Commit 730e54b

Browse files
committed
Merge branch 't/13388'
2 parents f23ff0c + 5eda40f commit 730e54b

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Fixed Issues:
2020
* [#13465](http://dev.ckeditor.com/ticket/13465): Fixed: Error is thrown and widget is lost when drag&drop if it is the only content of the editor.
2121
* [#13414](http://dev.ckeditor.com/ticket/13414): Fixed: Content auto paragraphing in a nested editable despite editor configuration.
2222
* [#13429](http://dev.ckeditor.com/ticket/13429): Fixed: Wrong selection after content insertion by [Auto Embed](http://ckeditor.com/addon/autoembed) plugin.
23+
* [#13388](http://dev.ckeditor.com/ticket/13388): Fixed: [Table Resize](http://ckeditor.com/addon/tableresize) integration with [Undo](http://ckeditor.com/addon/undo) is broken.
2324

2425
Other Changes:
2526

plugins/tableresize/plugin.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@
210210

211211
function resizeColumn() {
212212
var rtl = pillar.rtl,
213-
cellsCount = rtl ? rightSideCells.length : leftSideCells.length;
213+
cellsCount = rtl ? rightSideCells.length : leftSideCells.length,
214+
cellsSaved = 0;
214215

215216
// Perform the actual resize to table cells, only for those by side of the pillar.
216217
for ( var i = 0; i < cellsCount; i++ ) {
@@ -227,6 +228,12 @@
227228
// If we're in the last cell, we need to resize the table as well
228229
if ( tableWidth )
229230
table.setStyle( 'width', pxUnit( tableWidth + sizeShift * ( rtl ? -1 : 1 ) ) );
231+
232+
// Cells resizing is asynchronous-y, so we have to use syncing
233+
// to save snapshot only after all cells are resized. (#13388)
234+
if ( ++cellsSaved == cellsCount ) {
235+
editor.fire( 'saveSnapshot' );
236+
}
230237
}, 0, this, [
231238
leftCell, leftCell && getWidth( leftCell ),
232239
rightCell, rightCell && getWidth( rightCell ),
@@ -239,6 +246,8 @@
239246
function onMouseDown( evt ) {
240247
cancel( evt );
241248

249+
// Save editor's state before we do any magic with cells. (#13388)
250+
editor.fire( 'saveSnapshot' );
242251
resizeStart();
243252

244253
document.on( 'mouseup', onMouseUp, this );
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div id="editor">
2+
</div>
3+
4+
<script>
5+
CKEDITOR.replace( 'editor' );
6+
</script>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@bender-ui: collapsed
2+
@bender-tags: tc, 4.5.3, 13388
3+
@bender-ckeditor-plugins: wysiwygarea, toolbar, table, tableresize, basicstyles, undo
4+
5+
1. Insert a table.
6+
2. Type `1`.
7+
3. Click in a focused cell.
8+
4. Resize the left column.
9+
5. Type `2`.
10+
6. Resize the left column.
11+
7. Type `3`.
12+
8. Resize the whole table.
13+
14+
**Expected**: There should be 7 undo steps available. One for each action.
15+
16+
**Unexpected**: When undoing, a number is removed AND column changes size.

tests/plugins/tableresize/tableresize.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ <h1>Foo</h1>
3737
</tr>
3838
</tbody>
3939
</table>
40+
41+
<textarea id="undo">
42+
&lt;table border="1"&gt;
43+
&lt;tbody&gt;
44+
&lt;tr&gt;
45+
&lt;td&gt;&lt;/td&gt;
46+
&lt;/tr&gt;
47+
&lt;/tbody&gt;
48+
&lt;/table&gt;
49+
</textarea>

tests/plugins/tableresize/tableresize.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* bender-tags: editor,unit */
2-
/* bender-ckeditor-plugins: stylesheetparser,tableresize,wysiwygarea */
2+
/* bender-ckeditor-plugins: stylesheetparser,tableresize,wysiwygarea,undo */
33

44
'use strict';
55

@@ -97,6 +97,9 @@ bender.editors = {
9797
intable: {
9898
name: 'intable',
9999
creator: 'inline'
100+
},
101+
undo: {
102+
name: 'undo'
100103
}
101104
};
102105

@@ -186,5 +189,45 @@ bender.test( {
186189
editor.editable().fire( 'mousemove', evt );
187190

188191
assert.isNull( wrapperTable.getCustomData( '_cke_table_pillars' ) );
192+
},
193+
194+
// #13388.
195+
'test undo/redo table resize': function() {
196+
var editor = this.editors.undo,
197+
doc = editor.document,
198+
insideTable = doc.getElementsByTag( 'table' ).getItem( 0 );
199+
200+
init( insideTable, editor );
201+
202+
insideTable.findOne( 'td' ).setHtml( 'foo' );
203+
204+
resize( insideTable, function() {
205+
resume( function() {
206+
var table;
207+
208+
// Step 1: undo table resizing.
209+
editor.execCommand( 'undo' );
210+
table = doc.findOne( 'table' );
211+
this.assertIsNotTouched( table, 'insideTable' );
212+
// Contents of table cell should remain not undone.
213+
assert.isInnerHtmlMatching( 'foo@', table.findOne( 'td' ).getHtml() );
214+
215+
// Step 2: undo text insert.
216+
editor.execCommand( 'undo' );
217+
// Bogus elements may be present.
218+
assert.isInnerHtmlMatching( '@', doc.findOne( 'td' ).getHtml() );
219+
220+
// Get back to the "final" state with redo commands.
221+
// Redo text insert.
222+
editor.execCommand( 'redo' );
223+
// Redo table resize.
224+
editor.execCommand( 'redo' );
225+
226+
// Table should be resized.
227+
this.assertIsResized( doc.findOne( 'table' ), 'insideTable' );
228+
} );
229+
} );
230+
231+
wait();
189232
}
190233
} );

0 commit comments

Comments
 (0)