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

Commit 1dfdc83

Browse files
authored
Merge pull request #22 from ckeditor/t/ckeditor5-engine/1164
Other: Widgets highlight remove handler will now use only descriptor id, instead of the full descriptor.
2 parents e8f526d + 3d48537 commit 1dfdc83

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/highlightstack.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ export default class HighlightStack {
5454
* Removes highlight descriptor from the stack.
5555
*
5656
* @fires change:top
57-
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
57+
* @param {String} id Id of the descriptor to remove.
5858
*/
59-
remove( descriptor ) {
59+
remove( id ) {
6060
const stack = this._stack;
6161

6262
const oldTop = stack[ 0 ];
63-
this._removeDescriptor( descriptor );
63+
this._removeDescriptor( id );
6464
const newTop = stack[ 0 ];
6565

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

117117
// If descriptor with same id is on the list - remove it.
118118
if ( index > -1 ) {

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function setHighlightHandling( element, add, remove ) {
9696
} );
9797

9898
element.setCustomProperty( 'addHighlight', ( element, descriptor ) => stack.add( descriptor ) );
99-
element.setCustomProperty( 'removeHighlight', ( element, descriptor ) => stack.remove( descriptor ) );
99+
element.setCustomProperty( 'removeHighlight', ( element, id ) => stack.remove( id ) );
100100
}
101101

102102
/**

tests/highlightstack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe( 'HighlightStack', () => {
7979

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

82-
stack.remove( secondDescriptor );
82+
stack.remove( secondDescriptor.id );
8383

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

144144
stack.add( descriptor );
145145
stack.on( 'change:top', spy );
146-
stack.remove( descriptor );
146+
stack.remove( descriptor.id );
147147

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

163163
sinon.assert.notCalled( spy );
164164
} );

tests/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe( 'widget utils', () => {
6262
set( element, { priority: 1, class: 'highlight', id: 'highlight' } );
6363
expect( element.hasClass( 'highlight' ) ).to.be.true;
6464

65-
remove( element, { priority: 1, class: 'highlight', id: 'highlight' } );
65+
remove( element, 'highlight' );
6666
expect( element.hasClass( 'highlight' ) ).to.be.false;
6767
} );
6868

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

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

179179
set( element, descriptor );
180-
remove( element, descriptor );
180+
remove( element, descriptor.id );
181181

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

216216
set( element, descriptor );
217217
set( element, secondDescriptor );
218-
remove( element, secondDescriptor );
218+
remove( element, secondDescriptor.id );
219219

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

0 commit comments

Comments
 (0)