From f8d6b3f0d8e8272629851e6f0b9cc3f2becd2b0e Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 24 Jun 2015 11:21:44 +0200 Subject: [PATCH 1/7] Integrated tableresize with undo plugin. --- plugins/tableresize/plugin.js | 12 +++++++- tests/plugins/tableresize/tableresize.html | 10 +++++++ tests/plugins/tableresize/tableresize.js | 32 +++++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/plugins/tableresize/plugin.js b/plugins/tableresize/plugin.js index 53386082372..28eb3a1b81a 100644 --- a/plugins/tableresize/plugin.js +++ b/plugins/tableresize/plugin.js @@ -210,7 +210,8 @@ function resizeColumn() { var rtl = pillar.rtl, - cellsCount = rtl ? rightSideCells.length : leftSideCells.length; + cellsCount = rtl ? rightSideCells.length : leftSideCells.length, + cellsSaved = 0; // Perform the actual resize to table cells, only for those by side of the pillar. for ( var i = 0; i < cellsCount; i++ ) { @@ -227,6 +228,13 @@ // If we're in the last cell, we need to resize the table as well if ( tableWidth ) table.setStyle( 'width', pxUnit( tableWidth + sizeShift * ( rtl ? -1 : 1 ) ) ); + + // Cells resizing is asynchronous-y, so we have to use syncing + // to save snapshot only after all cells are resized. (#13388) + if ( ++cellsSaved == cellsCount ) { + editor.fire( 'unlockSnapshot' ); + editor.fire( 'saveSnapshot' ); + } }, 0, this, [ leftCell, leftCell && getWidth( leftCell ), rightCell, rightCell && getWidth( rightCell ), @@ -239,6 +247,8 @@ function onMouseDown( evt ) { cancel( evt ); + // Save editor's state before we do any magic with cells. (#13388) + editor.fire( 'lockSnapshot', { dontUpdate: true } ); resizeStart(); document.on( 'mouseup', onMouseUp, this ); diff --git a/tests/plugins/tableresize/tableresize.html b/tests/plugins/tableresize/tableresize.html index f03b5470ca1..f0d97bc22ed 100644 --- a/tests/plugins/tableresize/tableresize.html +++ b/tests/plugins/tableresize/tableresize.html @@ -37,3 +37,13 @@

Foo

+ + diff --git a/tests/plugins/tableresize/tableresize.js b/tests/plugins/tableresize/tableresize.js index 02595a64776..1fd2ea11803 100644 --- a/tests/plugins/tableresize/tableresize.js +++ b/tests/plugins/tableresize/tableresize.js @@ -1,5 +1,5 @@ /* bender-tags: editor,unit */ -/* bender-ckeditor-plugins: stylesheetparser,tableresize,wysiwygarea */ +/* bender-ckeditor-plugins: stylesheetparser,tableresize,wysiwygarea,undo */ 'use strict'; @@ -97,6 +97,9 @@ bender.editors = { intable: { name: 'intable', creator: 'inline' + }, + undo: { + name: 'undo' } }; @@ -186,5 +189,32 @@ bender.test( { editor.editable().fire( 'mousemove', evt ); assert.isNull( wrapperTable.getCustomData( '_cke_table_pillars' ) ); + }, + + // #13388. + 'test undo/redo table resize': function() { + var editor = this.editors.undo, + doc = editor.document, + insideTable = doc.getElementsByTag( 'table' ).getItem( 0 ), + changed = 0; + + editor.on( 'change', function() { + changed++; + } ); + + init( insideTable, editor ); + + resize( insideTable, function() { + resume( function() { + editor.execCommand( 'undo' ); + this.assertIsNotTouched( doc.getElementsByTag( 'table' ).getItem( 0 ), 'insideTable' ); + editor.execCommand( 'redo' ); + this.assertIsResized( doc.getElementsByTag( 'table' ).getItem( 0 ), 'insideTable' ); + + assert.isTrue( changed >= 3, 'Editor fired change event at least once for each resize/undo/redo' ); + } ); + } ); + + wait(); } } ); From 1beb8b561a10e1095be9d9e42b26497138055152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Thu, 6 Aug 2015 16:37:59 +0200 Subject: [PATCH 2/7] Tests: Added a manual test. --- tests/plugins/tableresize/manual/undo.html | 6 ++++++ tests/plugins/tableresize/manual/undo.md | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/plugins/tableresize/manual/undo.html create mode 100644 tests/plugins/tableresize/manual/undo.md diff --git a/tests/plugins/tableresize/manual/undo.html b/tests/plugins/tableresize/manual/undo.html new file mode 100644 index 00000000000..4446b08ff10 --- /dev/null +++ b/tests/plugins/tableresize/manual/undo.html @@ -0,0 +1,6 @@ +
+
+ + \ No newline at end of file diff --git a/tests/plugins/tableresize/manual/undo.md b/tests/plugins/tableresize/manual/undo.md new file mode 100644 index 00000000000..977ff284aa3 --- /dev/null +++ b/tests/plugins/tableresize/manual/undo.md @@ -0,0 +1,10 @@ +@bender-ui: collapsed +@bender-tags: tc, 4.5.3, 13388 +@bender-ckeditor-plugins: wysiwygarea, toolbar, table, tableresize, basicstyles, undo + +1. Insert a table. +2. Type few letters in one of its cells. +3. Resize the left column. +4. Resize the whole table. + +Expected: There should be 4 undo steps available. One for each action. \ No newline at end of file From 6b18f05065165a709838c2696568a23ee45f56b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Thu, 6 Aug 2015 16:38:57 +0200 Subject: [PATCH 3/7] Every action which makes one, separate undo step requires taking snapshot before and after itself. --- plugins/tableresize/plugin.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/tableresize/plugin.js b/plugins/tableresize/plugin.js index 28eb3a1b81a..44ddf9107b9 100644 --- a/plugins/tableresize/plugin.js +++ b/plugins/tableresize/plugin.js @@ -232,7 +232,6 @@ // Cells resizing is asynchronous-y, so we have to use syncing // to save snapshot only after all cells are resized. (#13388) if ( ++cellsSaved == cellsCount ) { - editor.fire( 'unlockSnapshot' ); editor.fire( 'saveSnapshot' ); } }, 0, this, [ @@ -248,7 +247,7 @@ cancel( evt ); // Save editor's state before we do any magic with cells. (#13388) - editor.fire( 'lockSnapshot', { dontUpdate: true } ); + editor.fire( 'saveSnapshot' ); resizeStart(); document.on( 'mouseup', onMouseUp, this ); From 1ab330d7addd8c848fbb7a313c9f0eeb4ebc190e Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 12 Aug 2015 09:21:35 +0200 Subject: [PATCH 4/7] Improved unit test for tableresize. --- tests/plugins/tableresize/tableresize.html | 2 +- tests/plugins/tableresize/tableresize.js | 32 ++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/plugins/tableresize/tableresize.html b/tests/plugins/tableresize/tableresize.html index f0d97bc22ed..5cb8d324423 100644 --- a/tests/plugins/tableresize/tableresize.html +++ b/tests/plugins/tableresize/tableresize.html @@ -42,7 +42,7 @@

Foo

<table border="1"> <tbody> <tr> - <td>bar</td> + <td></td> </tr> </tbody> </table> diff --git a/tests/plugins/tableresize/tableresize.js b/tests/plugins/tableresize/tableresize.js index 1fd2ea11803..1017bb23c24 100644 --- a/tests/plugins/tableresize/tableresize.js +++ b/tests/plugins/tableresize/tableresize.js @@ -195,23 +195,37 @@ bender.test( { 'test undo/redo table resize': function() { var editor = this.editors.undo, doc = editor.document, - insideTable = doc.getElementsByTag( 'table' ).getItem( 0 ), - changed = 0; - - editor.on( 'change', function() { - changed++; - } ); + insideTable = doc.getElementsByTag( 'table' ).getItem( 0 ); init( insideTable, editor ); + insideTable.find( 'td' ).getItem( 0 ).$.innerHTML = 'foo'; + resize( insideTable, function() { resume( function() { + var table; + + // Step 1: undo table resizing. editor.execCommand( 'undo' ); - this.assertIsNotTouched( doc.getElementsByTag( 'table' ).getItem( 0 ), 'insideTable' ); + table = doc.getElementsByTag( 'table' ).getItem( 0 ); + this.assertIsNotTouched( table, 'insideTable' ); + // Contents of table cell should remain not undone. + assert.isInnerHtmlMatching( 'foo@', table.find( 'td' ).getItem( 0 ).$.innerHTML ); + + // Step 2: undo text insert. + editor.execCommand( 'undo' ); + table = doc.getElementsByTag( 'table' ).getItem( 0 ); + // Bogus elements may be present. + assert.isInnerHtmlMatching( '@', table.find( 'td' ).getItem( 0 ).$.innerHTML ); + + // Get back to the "final" state with redo commands. + // Redo text insert. + editor.execCommand( 'redo' ); + // Redo table resize. editor.execCommand( 'redo' ); - this.assertIsResized( doc.getElementsByTag( 'table' ).getItem( 0 ), 'insideTable' ); - assert.isTrue( changed >= 3, 'Editor fired change event at least once for each resize/undo/redo' ); + // Table should be resized. + this.assertIsResized( doc.getElementsByTag( 'table' ).getItem( 0 ), 'insideTable' ); } ); } ); From 51b10220d17b650c687b55617d67318e09fe90eb Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Wed, 12 Aug 2015 14:30:10 +0200 Subject: [PATCH 5/7] Tests: Simplified code of tabletools resize test. --- tests/plugins/tableresize/tableresize.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/plugins/tableresize/tableresize.js b/tests/plugins/tableresize/tableresize.js index 1017bb23c24..e6671f00ccf 100644 --- a/tests/plugins/tableresize/tableresize.js +++ b/tests/plugins/tableresize/tableresize.js @@ -199,7 +199,7 @@ bender.test( { init( insideTable, editor ); - insideTable.find( 'td' ).getItem( 0 ).$.innerHTML = 'foo'; + insideTable.findOne( 'td' ).setHtml( 'foo' ); resize( insideTable, function() { resume( function() { @@ -207,16 +207,15 @@ bender.test( { // Step 1: undo table resizing. editor.execCommand( 'undo' ); - table = doc.getElementsByTag( 'table' ).getItem( 0 ); + table = doc.findOne( 'table' ); this.assertIsNotTouched( table, 'insideTable' ); // Contents of table cell should remain not undone. - assert.isInnerHtmlMatching( 'foo@', table.find( 'td' ).getItem( 0 ).$.innerHTML ); + assert.isInnerHtmlMatching( 'foo@', table.findOne( 'td' ).getHtml() ); // Step 2: undo text insert. editor.execCommand( 'undo' ); - table = doc.getElementsByTag( 'table' ).getItem( 0 ); // Bogus elements may be present. - assert.isInnerHtmlMatching( '@', table.find( 'td' ).getItem( 0 ).$.innerHTML ); + assert.isInnerHtmlMatching( '@', doc.findOne( 'td' ).getHtml() ); // Get back to the "final" state with redo commands. // Redo text insert. @@ -225,7 +224,7 @@ bender.test( { editor.execCommand( 'redo' ); // Table should be resized. - this.assertIsResized( doc.getElementsByTag( 'table' ).getItem( 0 ), 'insideTable' ); + this.assertIsResized( doc.findOne( 'table' ), 'insideTable' ); } ); } ); From 627bbacc6a88ab76b97230153275166083a90d3b Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 12 Aug 2015 15:21:39 +0200 Subject: [PATCH 6/7] Tableresize: extended manual test. --- tests/plugins/tableresize/manual/undo.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/plugins/tableresize/manual/undo.md b/tests/plugins/tableresize/manual/undo.md index 977ff284aa3..4615419a7f6 100644 --- a/tests/plugins/tableresize/manual/undo.md +++ b/tests/plugins/tableresize/manual/undo.md @@ -3,8 +3,14 @@ @bender-ckeditor-plugins: wysiwygarea, toolbar, table, tableresize, basicstyles, undo 1. Insert a table. -2. Type few letters in one of its cells. -3. Resize the left column. -4. Resize the whole table. +2. Type `1`. +3. Click in a focused cell. +4. Resize the left column. +5. Type `2`. +6. Resize the left column. +7. Type `3`. +8. Resize the whole table. -Expected: There should be 4 undo steps available. One for each action. \ No newline at end of file +**Expected**: There should be 7 undo steps available. One for each action. + +**Unexpected**: When undoing, a number is removed AND column changes size. From 5eda40fd2ae631be71f53deaf871e180b57795ec Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Wed, 12 Aug 2015 15:51:17 +0200 Subject: [PATCH 7/7] Changelog entry. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 55d863f8793..b56bf6631e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ Fixed Issues: * [#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. * [#13414](http://dev.ckeditor.com/ticket/13414): Fixed: Content auto paragraphing in a nested editable despite editor configuration. * [#13429](http://dev.ckeditor.com/ticket/13429): Fixed: Wrong selection after content insertion by [Auto Embed](http://ckeditor.com/addon/autoembed) plugin. +* [#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. Other Changes: