diff --git a/CHANGES.md b/CHANGES.md index 814668e72d2..a2dcc560c53 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ Fixed Issues: * [#808](https://github.com/ckeditor/ckeditor-dev/issues/808): Fixed: [Widget](https://ckeditor.com/cke4/addon/widget) and other content disappear on drag and drop in [read-only mode](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html). * [#3260](https://github.com/ckeditor/ckeditor-dev/issues/3260): Fixed: [Widget](https://ckeditor.com/cke4/addon/widget) drag handler is visible in [read-only mode](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html). +* [#941](https://github.com/ckeditor/ckeditor-dev/issues/941): Fixed: Error is thrown after styling the text table cell selected using native selection when [Table Selection](https://ckeditor.com/cke4/addon/tableselection) is enabled. ## CKEditor 4.12.1 diff --git a/core/style.js b/core/style.js index 9fbe22b2359..12c47e1241b 100644 --- a/core/style.js +++ b/core/style.js @@ -1830,25 +1830,13 @@ CKEDITOR.STYLE_OBJECT = 3; function applyStyleOnSelection( selection, remove, editor ) { var ranges = selection.getRanges(), func = remove ? this.removeFromRange : this.applyToRange, - originalRanges, - range, - i; - - // In case of fake table selection, we would like to apply all styles and then select - // the original ranges. Otherwise browsers would complain about discontiguous selection. - if ( selection.isFake && selection.isInTable() ) { - originalRanges = []; - - for ( i = 0; i < ranges.length; i++ ) { - originalRanges.push( ranges[ i ].clone() ); - } - } + range; var iterator = ranges.createIterator(); while ( ( range = iterator.getNextRange() ) ) func.call( this, range, editor ); - selection.selectRanges( originalRanges || ranges ); + selection.selectRanges( ranges ); } } )(); diff --git a/tests/plugins/tableselection/integrations/basicstyles/basicstyles.html b/tests/plugins/tableselection/integrations/basicstyles/basicstyles.html new file mode 100644 index 00000000000..247460af88c --- /dev/null +++ b/tests/plugins/tableselection/integrations/basicstyles/basicstyles.html @@ -0,0 +1,10 @@ + diff --git a/tests/plugins/tableselection/integrations/basicstyles/basicstyles.js b/tests/plugins/tableselection/integrations/basicstyles/basicstyles.js new file mode 100644 index 00000000000..2bdd89fed3e --- /dev/null +++ b/tests/plugins/tableselection/integrations/basicstyles/basicstyles.js @@ -0,0 +1,46 @@ +/* bender-tags: editor, tableselection */ +/* bender-ckeditor-plugins: basicstyles,tabletools,toolbar,tableselection */ + +( function() { + 'use strict'; + + bender.editor = {}; + + var tests = { + setUp: function() { + bender.tools.ignoreUnsupportedEnvironment( 'tableselection' ); + }, + + // (#941) + 'test toggle style': function() { + var editor = this.editor; + + this.editorBot.setHtmlWithSelection( CKEDITOR.document.getById( 'table' ).getValue() ); + + var cell = editor.editable().findOne( 'td' ); + + editor.getSelection().fake( cell ); + + selectElement( editor, cell ); + + editor.execCommand( 'bold' ); + + assert.areEqual( 'strong', cell.getFirst().getName(), 'Cell should be bolded' ); + + selectElement( editor, cell.findOne( 'strong' ) ); + + editor.execCommand( 'bold' ); + + assert.areEqual( CKEDITOR.NODE_TEXT, cell.getFirst().type, 'Cell should be unbolded' ); + } + }; + + bender.test( tests ); + + function selectElement( editor, element ) { + var range = editor.createRange(); + range.setStartAt( element, CKEDITOR.POSITION_AFTER_START ); + range.setEndAt( element, CKEDITOR.POSITION_BEFORE_END ); + range.select(); + } +} )(); diff --git a/tests/plugins/tableselection/manual/integrations/basicstyles/native.html b/tests/plugins/tableselection/manual/integrations/basicstyles/native.html new file mode 100644 index 00000000000..04c944efc53 --- /dev/null +++ b/tests/plugins/tableselection/manual/integrations/basicstyles/native.html @@ -0,0 +1,48 @@ +
+

Some text

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Cell 1.1Cell 1.2Cell 1.3Cell 1.4
Cell 2.1Cell 2.2Cell 2.3Cell 2.4
Cell 3.1Cell 3.2Cell 3.3Cell 3.4
Cell 4.1Cell 4.2Cell 4.3Cell 4.4
Cell 5.1Cell 5.2Cell 5.3Cell 5.4
+ +

Some text

+
+ + diff --git a/tests/plugins/tableselection/manual/integrations/basicstyles/native.md b/tests/plugins/tableselection/manual/integrations/basicstyles/native.md new file mode 100644 index 00000000000..11286ef9f0a --- /dev/null +++ b/tests/plugins/tableselection/manual/integrations/basicstyles/native.md @@ -0,0 +1,16 @@ +@bender-ui: collapsed +@bender-tags: bug, 4.13.0, 941 +@bender-ckeditor-plugins: wysiwygarea, toolbar, tableselection, basicstyles + +1. Open console. +2. Select the first cell text using native selection. +3. Click `Bold` button. + +**Expected**: Text is bolded, selection changes into visual selection. + +4. Click `Bold` button again. + +**Expected:** Text is unbolded, visual selection is preserved. + +**Unexpected**: Console registers exception. +