@@ -312,18 +312,14 @@ class Minimap {
312312 this . pendingChangeEvents = this . pendingChangeEvents . concat ( changes )
313313
314314 // Optimisation: If the redraw delay is set to 0, do not even schedule a timer
315- if ( ! this . redrawDelay && ! this . requestedFlushChanges ) {
316- this . requestedFlushChanges = true
317- requestAnimationFrame ( ( ) => { this . flushChanges ( ) ; this . requestedFlushChanges = false } )
315+ if ( ! this . redrawDelay ) {
316+ this . requestFlushChanges ( )
318317 }
319318
320- if ( ! this . flushChangesTimer && ! this . requestedFlushChanges ) {
319+ if ( ! this . flushChangesTimer ) {
321320 // If any changes happened within the timeout's delay, a timeout will already have been
322321 // scheduled -> no need to schedule again
323- this . requestedFlushChanges = true
324- this . flushChangesTimer = setTimeout (
325- ( ) => { requestAnimationFrame ( ( ) => { this . flushChanges ( ) ; this . requestedFlushChanges = false } ) }
326- , this . redrawDelay )
322+ this . flushChangesTimer = setTimeout ( ( ) => { this . requestFlushChanges ( ) } , this . redrawDelay )
327323 }
328324 }
329325
@@ -340,6 +336,24 @@ class Minimap {
340336 this . pendingChangeEvents = [ ]
341337 }
342338
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+
343357 /**
344358 * Registers an event listener to the `did-change` event.
345359 *
0 commit comments