File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -313,13 +313,13 @@ class Minimap {
313313
314314 // Optimisation: If the redraw delay is set to 0, do not even schedule a timer
315315 if ( ! this . redrawDelay ) {
316- return this . flushChanges ( )
316+ this . requestFlushChanges ( )
317317 }
318318
319319 if ( ! this . flushChangesTimer ) {
320320 // If any changes happened within the timeout's delay, a timeout will already have been
321321 // scheduled -> no need to schedule again
322- this . flushChangesTimer = setTimeout ( ( ) => { this . flushChanges ( ) } , this . redrawDelay )
322+ this . flushChangesTimer = setTimeout ( ( ) => { this . requestFlushChanges ( ) } , this . redrawDelay )
323323 }
324324 }
325325
@@ -336,6 +336,24 @@ class Minimap {
336336 this . pendingChangeEvents = [ ]
337337 }
338338
339+ /**
340+ * Requests flush changes if not already requested
341+ *
342+ * @return void
343+ * @access private
344+ */
345+ requestFlushChanges ( ) {
346+ if ( ! this . requestedFlushChanges ) {
347+ this . requestedFlushChanges = requestAnimationFrame ( ( ) => {
348+ this . flushChanges ( )
349+ if ( this . requestedFlushChanges ) {
350+ cancelAnimationFrame ( this . requestedFlushChanges )
351+ this . requestedFlushChanges = null
352+ }
353+ } )
354+ }
355+ }
356+
339357 /**
340358 * Registers an event listener to the `did-change` event.
341359 *
Original file line number Diff line number Diff line change 246246 " requestAnimationFrame" ,
247247 " Event" ,
248248 " MouseEvent" ,
249- " IntersectionObserver"
249+ " IntersectionObserver" ,
250+ " cancelAnimationFrame"
250251 ]
251252 }
252253}
Original file line number Diff line number Diff line change @@ -89,7 +89,10 @@ describe('Minimap', () => {
8989
9090 editor . setText ( 'foo' )
9191
92- expect ( changeSpy ) . toHaveBeenCalled ( )
92+ // because of requestAnimation the change is relayed asynchronously.
93+ setTimeout ( ( ) => {
94+ expect ( changeSpy ) . toHaveBeenCalled ( )
95+ } , 1000 )
9396 } )
9497
9598 it ( 'relays scroll top events from the editor' , ( ) => {
You can’t perform that action at this time.
0 commit comments