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

Commit

Permalink
Merge pull request #259 from ckeditor/i/6107
Browse files Browse the repository at this point in the history
Feature: Brought the support for right–to–left languages to the table and table cell property forms. Closes ckeditor/ckeditor5#6107.
  • Loading branch information
oleq authored Mar 9, 2020
2 parents 3abc494 + b173029 commit 3a92fc4
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 20 deletions.
21 changes: 14 additions & 7 deletions src/tablecellproperties/ui/tablecellpropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export default class TableCellPropertiesView extends View {
// -- Horizontal ---------------------------------------------------

const horizontalAlignmentToolbar = new ToolbarView( locale );
const isContentRTL = this.locale.contentLanguageDirection === 'rtl';

horizontalAlignmentToolbar.set( {
isCompact: true,
Expand All @@ -695,7 +696,7 @@ export default class TableCellPropertiesView extends View {
labels: this._horizontalAlignmentLabels,
propertyName: 'horizontalAlignment',
nameToValue: name => {
return name === 'left' ? '' : name;
return name === ( isContentRTL ? 'right' : 'left' ) ? '' : name;
}
} );

Expand Down Expand Up @@ -781,14 +782,20 @@ export default class TableCellPropertiesView extends View {
* @type {Object.<String,String>}
*/
get _horizontalAlignmentLabels() {
const locale = this.locale;
const t = this.t;

return {
left: t( 'Align cell text to the left' ),
center: t( 'Align cell text to the center' ),
right: t( 'Align cell text to the right' ),
justify: t( 'Justify cell text' )
};
const left = t( 'Align cell text to the left' );
const center = t( 'Align cell text to the center' );
const right = t( 'Align cell text to the right' );
const justify = t( 'Justify cell text' );

// Returns object with a proper order of labels.
if ( locale.uiLanguageDirection === 'rtl' ) {
return { right, center, left, justify };
} else {
return { left, center, right, justify };
}
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/tableproperties/ui/tablepropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,19 @@ export default class TablePropertiesView extends View {
* @type {Object.<String,String>}
*/
get _alignmentLabels() {
const locale = this.locale;
const t = this.t;

return {
left: t( 'Align table to the left' ),
center: t( 'Center table' ),
right: t( 'Align table to the right' )
};
const left = t( 'Align table to the left' );
const center = t( 'Center table' );
const right = t( 'Align table to the right' );

// Returns object with a proper order of labels.
if ( locale.uiLanguageDirection === 'rtl' ) {
return { right, center, left };
} else {
return { left, center, right };
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/colorinputview.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class ColorInputView extends View {

dropdown.buttonView.children.add( colorPreview );

dropdown.panelPosition = 'sw';
dropdown.panelPosition = locale.uiLanguageDirection === 'rtl' ? 'se' : 'sw';
dropdown.panelView.children.add( removeColorButton );
dropdown.panelView.children.add( colorGrid );
dropdown.bind( 'isEnabled' ).to( this, 'isReadOnly', value => !value );
Expand Down
11 changes: 7 additions & 4 deletions tests/manual/rtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';

import TableProperties from '../../src/tableproperties';
import TableCellProperties from '../../src/tablecellproperties';

ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ ArticlePluginSet ],
plugins: [ ArticlePluginSet, TableProperties, TableCellProperties ],
language: {
ui: 'en',
content: 'ar'
ui: 'ar',
content: 'en'
},
toolbar: [
'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
],
table: {
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ],
tableToolbar: [ 'bold', 'italic' ]
}
} )
Expand Down
26 changes: 25 additions & 1 deletion tests/tablecellproperties/ui/tablecellpropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ describe( 'table cell properties', () => {
expect( toolbar.ariaLabel ).to.equal( 'Horizontal text alignment toolbar' );
} );

it( 'should bring alignment buttons', () => {
it( 'should bring alignment buttons in the right order (left-to-right UI)', () => {
expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
'Align cell text to the left',
'Align cell text to the center',
Expand All @@ -487,6 +487,30 @@ describe( 'table cell properties', () => {
] );
} );

it( 'should bring alignment buttons in the right order (right-to-left UI)', () => {
// Creates its own local instances of locale, view and toolbar.
const locale = {
t: val => val,
uiLanguageDirection: 'rtl',
contentLanguageDirection: 'rtl'
};
const view = new TableCellPropertiesView( locale, VIEW_OPTIONS );
const toolbar = view.horizontalAlignmentToolbar;

expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
'Align cell text to the right',
'Align cell text to the center',
'Align cell text to the left',
'Justify cell text'
] );

expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
true, false, false, false
] );

view.destroy();
} );

it( 'should change the #horizontalAlignment value', () => {
toolbar.items.last.fire( 'execute' );
expect( view.horizontalAlignment ).to.equal( 'justify' );
Expand Down
25 changes: 24 additions & 1 deletion tests/tableproperties/ui/tablepropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe( 'table properties', () => {
expect( toolbar.ariaLabel ).to.equal( 'Table alignment toolbar' );
} );

it( 'should bring alignment buttons', () => {
it( 'should bring alignment buttons in the right order (left-to-right UI)', () => {
expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
'Align table to the left',
'Center table',
Expand All @@ -451,6 +451,29 @@ describe( 'table properties', () => {
] );
} );

it( 'should bring alignment buttons in the right order (right-to-left UI)', () => {
// Creates its own local instances of locale, view and toolbar.
const locale = {
t: val => val,
uiLanguageDirection: 'rtl',
contentLanguageDirection: 'rtl'
};
const view = new TablePropertiesView( locale, VIEW_OPTIONS );
const toolbar = view.alignmentToolbar;

expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
'Align table to the right',
'Center table',
'Align table to the left'
] );

expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
false, true, false
] );

view.destroy();
} );

it( 'should change the #horizontalAlignment value', () => {
toolbar.items.last.fire( 'execute' );
expect( view.alignment ).to.equal( 'right' );
Expand Down
25 changes: 24 additions & 1 deletion tests/ui/colorinputview.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe( 'ColorInputView', () => {
it( 'should be created', () => {
expect( view._dropdownView ).to.be.instanceOf( DropdownView );
expect( view._dropdownView.buttonView.element.classList.contains( 'ck-input-color__button' ) ).to.be.true;
expect( view._dropdownView.panelPosition ).to.equal( 'sw' );
} );

it( 'should bind #isEnabled to the view\'s #isReadOnly', () => {
Expand Down Expand Up @@ -107,6 +106,30 @@ describe( 'ColorInputView', () => {
it( 'should have the remove color button', () => {
expect( view._dropdownView.panelView.children.first ).to.be.instanceOf( ButtonView );
} );

describe( 'position', () => {
it( 'should be SouthWest in LTR', () => {
locale.uiLanguageDirection = 'ltr';
view = new ColorInputView( locale, {
colorDefinitions: DEFAULT_COLORS,
columns: 5
} );
view.render();

expect( view._dropdownView.panelPosition ).to.equal( 'sw' );
} );

it( 'should be SouthEast in RTL', () => {
locale.uiLanguageDirection = 'rtl';
view = new ColorInputView( locale, {
colorDefinitions: DEFAULT_COLORS,
columns: 5
} );
view.render();

expect( view._dropdownView.panelPosition ).to.equal( 'se' );
} );
} );
} );

describe( 'color grid', () => {
Expand Down

0 comments on commit 3a92fc4

Please sign in to comment.