Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit ac7be7b

Browse files
authored
Merge pull request #218 from ckeditor/t/200c
Fix: Column insertion and cell merging buttons should work correctly when the editor content is right–to–left (RTL). Closes #200.
2 parents 2c70b67 + 2638a0c commit ac7be7b

File tree

5 files changed

+148
-6
lines changed

5 files changed

+148
-6
lines changed

src/tableui.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default class TableUI extends Plugin {
3838
init() {
3939
const editor = this.editor;
4040
const t = this.editor.t;
41+
const contentLanguageDirection = editor.locale.contentLanguageDirection;
42+
const isContentLtr = contentLanguageDirection === 'ltr';
4143

4244
editor.ui.componentFactory.add( 'insertTable', locale => {
4345
const command = editor.commands.get( 'insertTable' );
@@ -86,14 +88,14 @@ export default class TableUI extends Plugin {
8688
{
8789
type: 'button',
8890
model: {
89-
commandName: 'insertTableColumnLeft',
91+
commandName: isContentLtr ? 'insertTableColumnLeft' : 'insertTableColumnRight',
9092
label: t( 'Insert column left' )
9193
}
9294
},
9395
{
9496
type: 'button',
9597
model: {
96-
commandName: 'insertTableColumnRight',
98+
commandName: isContentLtr ? 'insertTableColumnRight' : 'insertTableColumnLeft',
9799
label: t( 'Insert column right' )
98100
}
99101
},
@@ -158,7 +160,7 @@ export default class TableUI extends Plugin {
158160
{
159161
type: 'button',
160162
model: {
161-
commandName: 'mergeTableCellRight',
163+
commandName: isContentLtr ? 'mergeTableCellRight' : 'mergeTableCellLeft',
162164
label: t( 'Merge cell right' )
163165
}
164166
},
@@ -172,7 +174,7 @@ export default class TableUI extends Plugin {
172174
{
173175
type: 'button',
174176
model: {
175-
commandName: 'mergeTableCellLeft',
177+
commandName: isContentLtr ? 'mergeTableCellLeft' : 'mergeTableCellRight',
176178
label: t( 'Merge cell left' )
177179
}
178180
},

tests/manual/rtl.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<style>
2+
body {
3+
font-family: Helvetica, Arial, sans-serif;
4+
font-size: 14px;
5+
}
6+
</style>
7+
8+
<div id="editor">
9+
<figure class="table">
10+
<table>
11+
<tbody>
12+
<tr>
13+
<td>1</td>
14+
<td>2</td>
15+
<td>3</td>
16+
</tr>
17+
<tr>
18+
<td>4</td>
19+
<td>5</td>
20+
<td>6</td>
21+
</tr>
22+
<tr>
23+
<td>7</td>
24+
<td>8</td>
25+
<td>9</td>
26+
</tr>
27+
</tbody>
28+
</table>
29+
</figure>
30+
</div>

tests/manual/rtl.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4+
*/
5+
6+
/* globals console, window, document */
7+
8+
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
9+
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
10+
11+
ClassicEditor
12+
.create( document.querySelector( '#editor' ), {
13+
plugins: [ ArticlePluginSet ],
14+
language: {
15+
ui: 'en',
16+
content: 'ar'
17+
},
18+
toolbar: [
19+
'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
20+
],
21+
table: {
22+
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
23+
tableToolbar: [ 'bold', 'italic' ]
24+
}
25+
} )
26+
.then( editor => {
27+
window.editor = editor;
28+
} )
29+
.catch( err => {
30+
console.error( err.stack );
31+
} );

tests/manual/rtl.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Tables and RTL (right–to–left) content
2+
3+
The editor has English UI and Arabic content. In Arabic, the table is mirrored so some features of the editor must work differently to provide the right UX.
4+
5+
## Adding columns
6+
7+
1. Focus the "5" cell.
8+
2. Using the toolbar menu, add column to the right.
9+
3. The column should visually appear on the right–hand side of the "5" cell.
10+
4. Focus the "5" cell.
11+
5. Using the toolbar menu, add column to the left.
12+
3. The column should visually appear on the left–hand side of the "5" cell.
13+
14+
## Merging cells
15+
16+
1. Focus the "5" cell.
17+
2. Using the toolbar menu, merge cell to the right.
18+
3. "5" and "4" cells should be merged.
19+
4. Focus the "5" cell.
20+
5. Using the toolbar menu, merge cell to the left.
21+
6. "5" and "6" cells should be merged.

tests/tableui.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe( 'TableUI', () => {
229229
expect( labels ).to.deep.equal( [ 'Header column', '|', 'Insert column left', 'Insert column right', 'Delete column' ] );
230230
} );
231231

232-
it( 'should bind items in panel to proper commands', () => {
232+
it( 'should bind items in panel to proper commands (LTR content)', () => {
233233
const items = dropdown.listView.items;
234234

235235
const setColumnHeaderCommand = editor.commands.get( 'setTableColumnHeader' );
@@ -266,6 +266,35 @@ describe( 'TableUI', () => {
266266
expect( dropdown.buttonView.isEnabled ).to.be.false;
267267
} );
268268

269+
it( 'should bind items in panel to proper commands (RTL content)', () => {
270+
const element = document.createElement( 'div' );
271+
272+
document.body.appendChild( element );
273+
274+
return ClassicTestEditor
275+
.create( element, {
276+
language: {
277+
ui: 'en',
278+
content: 'ar'
279+
},
280+
plugins: [ TableEditing, TableUI ]
281+
} )
282+
.then( editor => {
283+
const dropdown = editor.ui.componentFactory.create( 'tableColumn' );
284+
const items = dropdown.listView.items;
285+
286+
expect( items.get( 2 ).children.first.label ).to.equal( 'Insert column left' );
287+
expect( items.get( 2 ).children.first.commandName ).to.equal( 'insertTableColumnRight' );
288+
289+
expect( items.get( 3 ).children.first.label ).to.equal( 'Insert column right' );
290+
expect( items.get( 3 ).children.first.commandName ).to.equal( 'insertTableColumnLeft' );
291+
292+
element.remove();
293+
294+
return editor.destroy();
295+
} );
296+
} );
297+
269298
it( 'should focus view after command execution', () => {
270299
const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
271300

@@ -336,7 +365,7 @@ describe( 'TableUI', () => {
336365
] );
337366
} );
338367

339-
it( 'should bind items in panel to proper commands', () => {
368+
it( 'should bind items in panel to proper commands (LTR content)', () => {
340369
const items = dropdown.listView.items;
341370

342371
const mergeCellUpCommand = editor.commands.get( 'mergeTableCellUp' );
@@ -386,6 +415,35 @@ describe( 'TableUI', () => {
386415
expect( dropdown.buttonView.isEnabled ).to.be.false;
387416
} );
388417

418+
it( 'should bind items in panel to proper commands (RTL content)', () => {
419+
const element = document.createElement( 'div' );
420+
421+
document.body.appendChild( element );
422+
423+
return ClassicTestEditor
424+
.create( element, {
425+
language: {
426+
ui: 'en',
427+
content: 'ar'
428+
},
429+
plugins: [ TableEditing, TableUI ]
430+
} )
431+
.then( editor => {
432+
const dropdown = editor.ui.componentFactory.create( 'mergeTableCells' );
433+
const items = dropdown.listView.items;
434+
435+
expect( items.get( 1 ).children.first.label ).to.equal( 'Merge cell right' );
436+
expect( items.get( 1 ).children.first.commandName ).to.equal( 'mergeTableCellLeft' );
437+
438+
expect( items.get( 3 ).children.first.label ).to.equal( 'Merge cell left' );
439+
expect( items.get( 3 ).children.first.commandName ).to.equal( 'mergeTableCellRight' );
440+
441+
element.remove();
442+
443+
return editor.destroy();
444+
} );
445+
} );
446+
389447
it( 'should focus view after command execution', () => {
390448
const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
391449

0 commit comments

Comments
 (0)