Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 'Remove highlight' #12289

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/ckeditor5-highlight/src/highlightui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
18 changes: 18 additions & 0 deletions packages/ckeditor5-highlight/tests/highlightui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down Expand Up @@ -271,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;
Expand Down