@@ -171,16 +171,21 @@ describe( 'LiveSelection', () => {
171
171
selection . addRange ( liveRange ) ;
172
172
selection . addRange ( range ) ;
173
173
174
- const ranges = selection . _ranges ;
174
+ const ranges = Array . from ( selection . _ranges ) ;
175
175
176
176
sinon . spy ( ranges [ 0 ] , 'detach' ) ;
177
177
sinon . spy ( ranges [ 1 ] , 'detach' ) ;
178
178
179
+ sinon . spy ( selection , 'stopListening' ) ;
180
+
179
181
selection . destroy ( ) ;
180
182
181
183
expect ( ranges [ 0 ] . detach . called ) . to . be . true ;
182
184
expect ( ranges [ 1 ] . detach . called ) . to . be . true ;
183
185
186
+ expect ( selection . stopListening . calledWith ( ranges [ 0 ] ) ) . to . be . true ;
187
+ expect ( selection . stopListening . calledWith ( ranges [ 1 ] ) ) . to . be . true ;
188
+
184
189
ranges [ 0 ] . detach . restore ( ) ;
185
190
ranges [ 1 ] . detach . restore ( ) ;
186
191
} ) ;
@@ -226,6 +231,7 @@ describe( 'LiveSelection', () => {
226
231
sinon . spy ( ranges [ 0 ] , 'detach' ) ;
227
232
sinon . spy ( ranges [ 1 ] , 'detach' ) ;
228
233
234
+ sinon . spy ( selection , 'stopListening' ) ;
229
235
selection . removeAllRanges ( ) ;
230
236
} ) ;
231
237
@@ -240,7 +246,7 @@ describe( 'LiveSelection', () => {
240
246
expect ( selection . focus . isEqual ( new Position ( root , [ 0 , 0 ] ) ) ) . to . be . true ;
241
247
} ) ;
242
248
243
- it ( 'should detach ranges' , ( ) => {
249
+ it ( 'should detach ranges and stop listening to removed ranges ' , ( ) => {
244
250
expect ( ranges [ 0 ] . detach . called ) . to . be . true ;
245
251
expect ( ranges [ 1 ] . detach . called ) . to . be . true ;
246
252
} ) ;
@@ -261,7 +267,7 @@ describe( 'LiveSelection', () => {
261
267
} ) . to . throw ( CKEditorError , / m o d e l - s e l e c t i o n - a d d e d - n o t - r a n g e / ) ;
262
268
} ) ;
263
269
264
- it ( 'should detach removed ranges' , ( ) => {
270
+ it ( 'should detach and stop listening to removed ranges' , ( ) => {
265
271
selection . addRange ( liveRange ) ;
266
272
selection . addRange ( range ) ;
267
273
@@ -270,6 +276,8 @@ describe( 'LiveSelection', () => {
270
276
sinon . spy ( oldRanges [ 0 ] , 'detach' ) ;
271
277
sinon . spy ( oldRanges [ 1 ] , 'detach' ) ;
272
278
279
+ sinon . spy ( selection , 'stopListening' ) ;
280
+
273
281
selection . setRanges ( [ ] ) ;
274
282
275
283
expect ( oldRanges [ 0 ] . detach . called ) . to . be . true ;
@@ -599,6 +607,25 @@ describe( 'LiveSelection', () => {
599
607
600
608
expect ( selection . getFirstPosition ( ) . path ) . to . deep . equal ( [ 0 , 6 ] ) ;
601
609
} ) ;
610
+
611
+ it ( 'detach and stop listening to a range that ended up in in graveyard' , ( ) => {
612
+ selection . collapse ( new Position ( root , [ 1 , 3 ] ) ) ;
613
+
614
+ const range = selection . _ranges [ 0 ] ;
615
+
616
+ sinon . spy ( range , 'detach' ) ;
617
+ sinon . spy ( selection , 'stopListening' ) ;
618
+
619
+ doc . applyOperation ( wrapInDelta (
620
+ new RemoveOperation (
621
+ new Position ( root , [ 1 , 2 ] ) ,
622
+ 2 ,
623
+ doc . version
624
+ )
625
+ ) ) ;
626
+
627
+ expect ( range . detach . called ) . to . be . true ;
628
+ } ) ;
602
629
} ) ;
603
630
} ) ;
604
631
0 commit comments