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

Fixed: [tableselection] table contents can be removed in a readonly mode #1527

Merged
merged 10 commits into from
Sep 3, 2018
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:

* [#1181](https://github.com/ckeditor/ckeditor-dev/issues/1181): [Chrome] Fixed: Opening context menu in readonly editor results in error.
* [#2276](https://github.com/ckeditor/ckeditor-dev/issues/2276): [iOS] Fixed: [Button](https://ckeditor.com/cke4/addon/button) state doesn't refresh properly.
* [#1489](https://github.com/ckeditor/ckeditor-dev/issues/1489): Fixed: [Table Selection](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_plugins_tableselection.html) table contents can be removed in readonly mode.

## CKEditor 4.10.1

Expand Down
8 changes: 7 additions & 1 deletion plugins/tableselection/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,8 @@
i;

// Handle only left/right/del/bspace keys.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust comment and add reference to the issue.

if ( !keystrokes[ key ] ) {
// Disable editing cells in readonly mode (#1489).
if ( !keystrokes[ key ] || editor.readOnly ) {
return;
}

Expand Down Expand Up @@ -1043,6 +1044,11 @@
firstCell,
i;

// Disable editing cells in readonly mode (#1489).
if ( editor.readOnly ) {
return;
}

// We must check if the event really did not produce any character as it's fired for all keys in Gecko.
if ( !selection || !selection.isInTable() || !selection.isFake || !isCharKey ||
evt.data.getKeystroke() & CKEDITOR.CTRL ) {
Expand Down
32 changes: 32 additions & 0 deletions tests/plugins/tableselection/manual/readonly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div id="editor1">
<table border="1">
<tr>
<td>Cell 1.1.1</td>
<td>Cell 1.1.2</td>
<td>Cell 1.1.3</td>
<td>Cell 1.1.4</td>
</tr>
<tr>
<td>Cell 1.2.1</td>
<td>Cell 1.2.2</td>
<td>Cell 1.2.3</td>
<td>Cell 1.2.4</td>
</tr>
<tr>
<td>Cell 1.3.1</td>
<td>Cell 1.3.2</td>
<td>Cell 1.3.3</td>
<td>Cell 1.3.4</td>
</tr>
</table>
</div>

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

CKEDITOR.replace( 'editor1', {
readOnly : true
} );
</script>
17 changes: 17 additions & 0 deletions tests/plugins/tableselection/manual/readonly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@bender-ui: collapsed
@bender-tags: 1489, 4.10.2, bug
@bender-ckeditor-plugins: wysiwygarea, toolbar, tableselection

1. Focus the editor.
1. Select the first row in a table.
1. Press `backspace` key.
1. Repeat 1-3 with `delete` key.
1. Repeat 1-3 with `a`, `k` keys (random key validation).

## Expected

Selected row didn't change.

## Unexpected

Selected row has been deleted.
24 changes: 24 additions & 0 deletions tests/plugins/tableselection/tableselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@

assert.areSame( ranges, editor.getSelection().getRanges(), 'Selected ranges should be unchanged' );
} );
},

// (#1489)
'test random keys are not removing readonly selection': function( editor ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test is failing in IE11.

var selection = editor.getSelection(),
editable = editor.editable(),
table = CKEDITOR.document.getById( 'simpleTable' ).getHtml();

editor.setReadOnly( true );

bender.tools.setHtmlWithSelection( editor, table );

var row = editor.editable().findOne( 'tr' );
selection.selectElement( row );

editable.fire( 'keydown', new CKEDITOR.dom.event( { keyCode: 8 } ) ); // backspace
editable.fire( 'keydown', new CKEDITOR.dom.event( { keyCode: 46 } ) ); // delete

editable.fire( 'keypress', new CKEDITOR.dom.event( { keyCode: 65, charCode: 65 } ) ); // `a`
editable.fire( 'keypress', new CKEDITOR.dom.event( { keyCode: 93, charCode: 93 } ) ); // `t`

editor.setReadOnly( false );

assert.areSame( bender.tools.compatHtml( table ), editor.getData(), 'Editor data' );
}
};

Expand Down