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

Commit e5df329

Browse files
authored
Merge pull request #99 from ckeditor/t/ckeditor5/1151
Other: Made the undo and redo button icons match the editor UI language direction. See ckeditor/ckeditor5#1151.
2 parents 534a8dd + a74775b commit e5df329

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/undoui.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ export default class UndoUI extends Plugin {
2424
*/
2525
init() {
2626
const editor = this.editor;
27+
const locale = editor.locale;
2728
const t = editor.t;
2829

29-
this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', undoIcon );
30-
this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', redoIcon );
30+
const localizedUndoIcon = locale.uiLanguageDirection == 'ltr' ? undoIcon : redoIcon;
31+
const localizedRedoIcon = locale.uiLanguageDirection == 'ltr' ? redoIcon : undoIcon;
32+
33+
this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', localizedUndoIcon );
34+
this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', localizedRedoIcon );
3135
}
3236

3337
/**

tests/undoui.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import UndoUI from '../src/undoui';
1111
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
1212
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
1313

14+
import undoIcon from '../theme/icons/undo.svg';
15+
import redoIcon from '../theme/icons/redo.svg';
16+
1417
describe( 'UndoUI', () => {
1518
let editor, editorElement;
1619

@@ -35,6 +38,66 @@ describe( 'UndoUI', () => {
3538
testButton( 'undo', 'Undo', 'CTRL+Z' );
3639
testButton( 'redo', 'Redo', 'CTRL+Y' );
3740

41+
describe( 'icons', () => {
42+
describe( 'left–to–right UI', () => {
43+
it( 'should display the right icon for undo', () => {
44+
const undoButton = editor.ui.componentFactory.create( 'undo' );
45+
46+
expect( undoButton.icon ).to.equal( undoIcon );
47+
} );
48+
49+
it( 'should display the right icon for redo', () => {
50+
const redoButton = editor.ui.componentFactory.create( 'redo' );
51+
52+
expect( redoButton.icon ).to.equal( redoIcon );
53+
} );
54+
} );
55+
56+
describe( 'right–to–left UI', () => {
57+
it( 'should display the right icon for undo', () => {
58+
const element = document.createElement( 'div' );
59+
document.body.appendChild( element );
60+
61+
return ClassicTestEditor
62+
.create( element, {
63+
plugins: [ UndoEditing, UndoUI ],
64+
language: 'ar'
65+
} )
66+
.then( newEditor => {
67+
const undoButton = newEditor.ui.componentFactory.create( 'undo' );
68+
69+
expect( undoButton.icon ).to.equal( redoIcon );
70+
71+
return newEditor.destroy();
72+
} )
73+
.then( () => {
74+
element.remove();
75+
} );
76+
} );
77+
78+
it( 'should display the right icon for redo', () => {
79+
const element = document.createElement( 'div' );
80+
document.body.appendChild( element );
81+
82+
return ClassicTestEditor
83+
.create( element, {
84+
plugins: [ UndoEditing, UndoUI ],
85+
language: 'ar'
86+
} )
87+
.then( newEditor => {
88+
const redoButton = newEditor.ui.componentFactory.create( 'redo' );
89+
90+
expect( redoButton.icon ).to.equal( undoIcon );
91+
92+
return newEditor.destroy();
93+
} )
94+
.then( () => {
95+
element.remove();
96+
} );
97+
} );
98+
} );
99+
} );
100+
38101
function testButton( featureName, label, featureKeystroke ) {
39102
describe( `${ featureName } button`, () => {
40103
let button;

0 commit comments

Comments
 (0)