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

Enter modifies only first cell #447

Merged
merged 6 commits into from
Jun 5, 2017
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 @@ -9,6 +9,7 @@ New Features:

Fixed Issues:

* [#415](https://github.com/ckeditor/ckeditor-dev/issues/415): Fixed: [Firefox] Enter key breaks table structure when pressed in a table selection.
* [#457](https://github.com/ckeditor/ckeditor-dev/issues/457): Fixed: Error thrown when deleting content from the editor with no selection.
* [#450](https://github.com/ckeditor/ckeditor-dev/issues/450): Fixed: [`CKEDITOR.filter`](http://docs.ckeditor.com/#!/api/CKEDITOR.filter) incorrectly transforms `margin` CSS property.

Expand Down
4 changes: 3 additions & 1 deletion plugins/tableselection/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,14 @@

function tableKeyPressListener( evt ) {
var selection = editor.getSelection(),
// Enter key also produces character, but Firefox doesn't think so (gh#415).
isCharKey = evt.data.$.charCode || ( evt.data.getKey() === 13 ),
ranges,
firstCell,
i;

// 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 || !evt.data.$.charCode ||
if ( !selection || !selection.isInTable() || !selection.isFake || !isCharKey ||
evt.data.getKeystroke() & CKEDITOR.CTRL ) {
return;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/plugins/tableselection/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,26 @@
</tbody>
</table>
</textarea>

<textarea id="enterKey">
<table>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
</tr>
</table>

=>
<table>
<tbody>
<tr>
<td>^&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</textarea>
13 changes: 13 additions & 0 deletions tests/plugins/tableselection/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@
} );
keyTools.key.keyEvent( keyTools.key.keyCodesEnum.BACKSPACE );

bender.assert.beautified.html( expected, bot.htmlWithSelection() );
} );
},

// #415
'test enter key': function( editor, bot ) {
bender.tools.testInputOut( 'enterKey', function( source, expected ) {
bender.tools.setHtmlWithSelection( editor, source );

editor.getSelection().selectRanges( getRangesForCells( editor, [ 0, 1, 2, 3 ] ) );

editor.editable().fire( 'keypress', new CKEDITOR.dom.event( { keyCode: 13 } ) );

bender.assert.beautified.html( expected, bot.htmlWithSelection() );
} );
}
Expand Down
48 changes: 48 additions & 0 deletions tests/plugins/tableselection/manual/enterkey.html
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.gecko ) {
bender.ignore();
}

CKEDITOR.replace( 'editor1', {
autoGrow_onStartup: true
} );
</script>
13 changes: 13 additions & 0 deletions tests/plugins/tableselection/manual/enterkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@bender-ui: collapsed
@bender-tags: tc, gh415, 4.7.1
@bender-ckeditor-plugins: wysiwygarea, toolbar, tableselection, sourcearea, elementspath, undo

**Procedure:**

1. Select two or more table cells.
2. Press <kbd>Enter</kbd>.

**Expected result:**

* Visual selection is discarded.
* The new line is typed into the first selected table cell and collapsed selection is placed after it.