From 1ff482f668d5b5af54f8e14284dc4e8127824f11 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Mon, 29 Jul 2019 15:42:34 +0200 Subject: [PATCH 1/2] Made the undo and redo button icons match the editor UI language direction. --- src/undoui.js | 8 +++++-- tests/undoui.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/undoui.js b/src/undoui.js index b6efb75..540ad9f 100644 --- a/src/undoui.js +++ b/src/undoui.js @@ -24,10 +24,14 @@ export default class UndoUI extends Plugin { */ init() { const editor = this.editor; + const locale = editor.locale; const t = editor.t; - this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', undoIcon ); - this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', redoIcon ); + const localizedUndoIcon = locale.languageDirection == 'ltr' ? undoIcon : redoIcon; + const localizedRedoIcon = locale.languageDirection == 'ltr' ? redoIcon : undoIcon; + + this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', localizedUndoIcon ); + this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', localizedRedoIcon ); } /** diff --git a/tests/undoui.js b/tests/undoui.js index 04c7050..acffb9f 100644 --- a/tests/undoui.js +++ b/tests/undoui.js @@ -11,6 +11,9 @@ import UndoUI from '../src/undoui'; import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import undoIcon from '../theme/icons/undo.svg'; +import redoIcon from '../theme/icons/redo.svg'; + describe( 'UndoUI', () => { let editor, editorElement; @@ -35,6 +38,66 @@ describe( 'UndoUI', () => { testButton( 'undo', 'Undo', 'CTRL+Z' ); testButton( 'redo', 'Redo', 'CTRL+Y' ); + describe( 'icons', () => { + describe( 'left–to–right UI', () => { + it( 'should display the right icon for undo', () => { + const undoButton = editor.ui.componentFactory.create( 'undo' ); + + expect( undoButton.icon ).to.equal( undoIcon ); + } ); + + it( 'should display the right icon for redo', () => { + const redoButton = editor.ui.componentFactory.create( 'redo' ); + + expect( redoButton.icon ).to.equal( redoIcon ); + } ); + } ); + + describe( 'right–to–left UI', () => { + it( 'should display the right icon for undo', () => { + const element = document.createElement( 'div' ); + document.body.appendChild( element ); + + return ClassicTestEditor + .create( element, { + plugins: [ UndoEditing, UndoUI ], + language: 'ar' + } ) + .then( newEditor => { + const undoButton = newEditor.ui.componentFactory.create( 'undo' ); + + expect( undoButton.icon ).to.equal( redoIcon ); + + return newEditor.destroy(); + } ) + .then( () => { + element.remove(); + } ); + } ); + + it( 'should display the right icon for redo', () => { + const element = document.createElement( 'div' ); + document.body.appendChild( element ); + + return ClassicTestEditor + .create( element, { + plugins: [ UndoEditing, UndoUI ], + language: 'ar' + } ) + .then( newEditor => { + const redoButton = newEditor.ui.componentFactory.create( 'redo' ); + + expect( redoButton.icon ).to.equal( undoIcon ); + + return newEditor.destroy(); + } ) + .then( () => { + element.remove(); + } ); + } ); + } ); + } ); + function testButton( featureName, label, featureKeystroke ) { describe( `${ featureName } button`, () => { let button; From a74775b1eddce4d68d53a845bdd6607fac63af77 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Fri, 9 Aug 2019 15:56:04 +0200 Subject: [PATCH 2/2] Aligned the code to the latest Locale class API. --- src/undoui.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/undoui.js b/src/undoui.js index 540ad9f..1d285ca 100644 --- a/src/undoui.js +++ b/src/undoui.js @@ -27,8 +27,8 @@ export default class UndoUI extends Plugin { const locale = editor.locale; const t = editor.t; - const localizedUndoIcon = locale.languageDirection == 'ltr' ? undoIcon : redoIcon; - const localizedRedoIcon = locale.languageDirection == 'ltr' ? redoIcon : undoIcon; + const localizedUndoIcon = locale.uiLanguageDirection == 'ltr' ? undoIcon : redoIcon; + const localizedRedoIcon = locale.uiLanguageDirection == 'ltr' ? redoIcon : undoIcon; this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', localizedUndoIcon ); this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', localizedRedoIcon );