Skip to content

Commit 2ca5006

Browse files
committed
feat: use requestAnimationFrame for scheduleChanges
This allows skipping the frames if the browser is busy doing other things, and it will improve the overall experience
1 parent 7005a8f commit 2ca5006

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/minimap.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,18 @@ 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) {
316-
return this.flushChanges()
315+
if (!this.redrawDelay && !this.requestedFlushChanges) {
316+
this.requestedFlushChanges = true
317+
requestAnimationFrame(() => { this.flushChanges(); this.requestedFlushChanges = false })
317318
}
318319

319-
if (!this.flushChangesTimer) {
320+
if (!this.flushChangesTimer && !this.requestedFlushChanges) {
320321
// If any changes happened within the timeout's delay, a timeout will already have been
321322
// scheduled -> no need to schedule again
322-
this.flushChangesTimer = setTimeout(() => { this.flushChanges() }, this.redrawDelay)
323+
this.requestedFlushChanges = true
324+
this.flushChangesTimer = setTimeout(
325+
() => { requestAnimationFrame(() => { this.flushChanges(); this.requestedFlushChanges = false }) }
326+
, this.redrawDelay)
323327
}
324328
}
325329

0 commit comments

Comments
 (0)