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 #22 from ckeditor/t/ckeditor5-engine/1164
Browse files Browse the repository at this point in the history
Other: Widgets highlight remove handler will now use only descriptor id, instead of the full descriptor.
  • Loading branch information
scofalik authored Oct 16, 2017
2 parents e8f526d + 3d48537 commit 1dfdc83
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/highlightstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export default class HighlightStack {
* Removes highlight descriptor from the stack.
*
* @fires change:top
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
* @param {String} id Id of the descriptor to remove.
*/
remove( descriptor ) {
remove( id ) {
const stack = this._stack;

const oldTop = stack[ 0 ];
this._removeDescriptor( descriptor );
this._removeDescriptor( id );
const newTop = stack[ 0 ];

// When new object is at the top and stores different information.
Expand Down Expand Up @@ -108,11 +108,11 @@ export default class HighlightStack {
* Removes descriptor with given id from the stack.
*
* @private
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
* @param {String} id Descriptor's id.
*/
_removeDescriptor( descriptor ) {
_removeDescriptor( id ) {
const stack = this._stack;
const index = stack.findIndex( item => item.id === descriptor.id );
const index = stack.findIndex( item => item.id === id );

// If descriptor with same id is on the list - remove it.
if ( index > -1 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function setHighlightHandling( element, add, remove ) {
} );

element.setCustomProperty( 'addHighlight', ( element, descriptor ) => stack.add( descriptor ) );
element.setCustomProperty( 'removeHighlight', ( element, descriptor ) => stack.remove( descriptor ) );
element.setCustomProperty( 'removeHighlight', ( element, id ) => stack.remove( id ) );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/highlightstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe( 'HighlightStack', () => {

stack.on( 'change:top', spy );

stack.remove( secondDescriptor );
stack.remove( secondDescriptor.id );

sinon.assert.calledOnce( spy );
expect( spy.firstCall.args[ 1 ].oldDescriptor ).to.equal( secondDescriptor );
Expand Down Expand Up @@ -143,7 +143,7 @@ describe( 'HighlightStack', () => {

stack.add( descriptor );
stack.on( 'change:top', spy );
stack.remove( descriptor );
stack.remove( descriptor.id );

sinon.assert.calledOnce( spy );
expect( spy.firstCall.args[ 1 ].newDescriptor ).to.be.undefined;
Expand All @@ -158,7 +158,7 @@ describe( 'HighlightStack', () => {
stack.add( descriptor );
stack.add( secondDescriptor );
stack.on( 'change:top', spy );
stack.remove( secondDescriptor );
stack.remove( secondDescriptor.id );

sinon.assert.notCalled( spy );
} );
Expand Down
8 changes: 4 additions & 4 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe( 'widget utils', () => {
set( element, { priority: 1, class: 'highlight', id: 'highlight' } );
expect( element.hasClass( 'highlight' ) ).to.be.true;

remove( element, { priority: 1, class: 'highlight', id: 'highlight' } );
remove( element, 'highlight' );
expect( element.hasClass( 'highlight' ) ).to.be.false;
} );

Expand All @@ -79,7 +79,7 @@ describe( 'widget utils', () => {
expect( element.hasClass( 'highlight' ) ).to.be.true;
expect( element.hasClass( 'foo' ) ).to.be.true;

remove( element, { priority: 1, class: [ 'foo', 'highlight' ], id: 'highlight' } );
remove( element, 'highlight' );
expect( element.hasClass( 'highlight' ) ).to.be.false;
expect( element.hasClass( 'foo' ) ).to.be.false;
} );
Expand Down Expand Up @@ -177,7 +177,7 @@ describe( 'widget utils', () => {
const descriptor = { priority: 10, class: 'highlight', id: 'highlight' };

set( element, descriptor );
remove( element, descriptor );
remove( element, descriptor.id );

sinon.assert.calledOnce( addSpy );
sinon.assert.calledWithExactly( addSpy, element, descriptor );
Expand Down Expand Up @@ -215,7 +215,7 @@ describe( 'widget utils', () => {

set( element, descriptor );
set( element, secondDescriptor );
remove( element, secondDescriptor );
remove( element, secondDescriptor.id );

sinon.assert.calledThrice( addSpy );
expect( addSpy.firstCall.args[ 1 ] ).to.equal( descriptor );
Expand Down

0 comments on commit 1dfdc83

Please sign in to comment.