From 43a0033228f9561b739140b37da783653a05f1ca Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Thu, 18 Aug 2022 15:48:20 +0200 Subject: [PATCH 1/2] Fixes 'Remove highlight' --- packages/ckeditor5-highlight/src/highlightui.js | 7 +++++-- packages/ckeditor5-highlight/tests/highlightui.js | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-highlight/src/highlightui.js b/packages/ckeditor5-highlight/src/highlightui.js index b4859843a0c..ef662aabb60 100644 --- a/packages/ckeditor5-highlight/src/highlightui.js +++ b/packages/ckeditor5-highlight/src/highlightui.js @@ -227,10 +227,13 @@ export default class HighlightUI extends Plugin { dropdownView.toolbarView.ariaLabel = t( 'Text highlight toolbar' ); // Execute current action from dropdown's split button action button. - // Also focus the editable after executing the command. + splitButtonView.on( 'execute', () => { + editor.execute( 'highlight', { value: splitButtonView.commandValue } ); + } ); + + // Focus the editable after executing the command. // It overrides a default behaviour where the focus is moved to the dropdown button (#12125). this.listenTo( dropdownView, 'execute', () => { - editor.execute( 'highlight', { value: splitButtonView.commandValue } ); editor.editing.view.focus(); } ); diff --git a/packages/ckeditor5-highlight/tests/highlightui.js b/packages/ckeditor5-highlight/tests/highlightui.js index c60b230442a..d32f9a90477 100644 --- a/packages/ckeditor5-highlight/tests/highlightui.js +++ b/packages/ckeditor5-highlight/tests/highlightui.js @@ -189,6 +189,15 @@ describe( 'HighlightUI', () => { validateButton( 5 ); } ); + it( 'should execute the command only once', () => { + const executeSpy = sinon.spy( command, 'execute' ); + + buttons[ 5 ].fire( 'execute' ); + + sinon.assert.calledOnce( executeSpy ); + sinon.assert.calledWith( executeSpy, { value: 'greenPen' } ); + } ); + it( 'should focus view after command execution', () => { const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' ); From dd993afc61c3de370fe44b2fd6e41157dabf165b Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Thu, 18 Aug 2022 15:56:43 +0200 Subject: [PATCH 2/2] Fixes 'Remove highlight' - one more test --- packages/ckeditor5-highlight/tests/highlightui.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/ckeditor5-highlight/tests/highlightui.js b/packages/ckeditor5-highlight/tests/highlightui.js index d32f9a90477..be24e1903ec 100644 --- a/packages/ckeditor5-highlight/tests/highlightui.js +++ b/packages/ckeditor5-highlight/tests/highlightui.js @@ -280,6 +280,15 @@ describe( 'HighlightUI', () => { expect( removeHighlightButton ).to.have.property( 'icon', eraserIcon ); } ); + it( 'should execute the command only once', () => { + const executeSpy = sinon.spy( command, 'execute' ); + + removeHighlightButton.fire( 'execute' ); + + sinon.assert.calledOnce( executeSpy ); + sinon.assert.calledWith( executeSpy, { value: null } ); + } ); + describe( 'model to command binding', () => { it( 'isEnabled', () => { command.isEnabled = false;