Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for incorrect selection when styling table using native selection #3038

Merged
merged 4 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 2 additions & 14 deletions core/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
} )();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<textarea id="table">
<table>
<tbody>
<tr>
<td>Cell 1.1</td>
<td>Cell 1.2</td>
</tr>
</tbody>
</table>
</textarea>
Original file line number Diff line number Diff line change
@@ -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();
}
} )();
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div id="editor1">
<p>Some text</p>

<table border="1">
<tr>
<td>Cell 1.1</td>
<td>Cell 1.2</td>
<td>Cell 1.3</td>
<td>Cell 1.4</td>
</tr>
<tr>
<td>Cell 2.1</td>
<td>Cell 2.2</td>
<td>Cell 2.3</td>
<td>Cell 2.4</td>
</tr>
<tr>
<td>Cell 3.1</td>
<td>Cell 3.2</td>
<td>Cell 3.3</td>
<td>Cell 3.4</td>
</tr>
<tr>
<td>Cell 4.1</td>
<td>Cell 4.2</td>
<td>Cell 4.3</td>
<td>Cell 4.4</td>
</tr>
<tr>
<td>Cell 5.1</td>
<td>Cell 5.2</td>
<td>Cell 5.3</td>
<td>Cell 5.4</td>
</tr>
</table>

<p>Some text</p>
</div>

<script>
if ( ( CKEDITOR.env.ie && CKEDITOR.env.version < 11 ) || bender.tools.env.mobile ) {
bender.ignore();
}

CKEDITOR.replace( 'editor1', {
autoGrow_onStartup: true
} );
</script>
Original file line number Diff line number Diff line change
@@ -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.