mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Use MessageChannel-based nextTick to schedule Editor display update
This is the fastest way I've found to get the nextTick behavior, which allows us to aggregate multiple requests for display update (from selection changes, cursor movement, line changes) etc into a single call at the end of processing an event.
This commit is contained in:
@@ -734,7 +734,7 @@ class Editor extends View
|
||||
requestDisplayUpdate: ()->
|
||||
return if @pendingDisplayUpdate
|
||||
@pendingDisplayUpdate = true
|
||||
webkitRequestAnimationFrame =>
|
||||
_.nextTick =>
|
||||
@updateDisplay()
|
||||
@pendingDisplayUpdate = false
|
||||
|
||||
|
||||
@@ -71,4 +71,14 @@ _.mixin
|
||||
inverted
|
||||
|
||||
multiplyString: (string, n) ->
|
||||
new Array(1 + n).join(string)
|
||||
new Array(1 + n).join(string)
|
||||
|
||||
nextTick: (fn) ->
|
||||
unless @messageChannel
|
||||
@pendingNextTickFns = []
|
||||
@messageChannel = new MessageChannel
|
||||
@messageChannel.port1.onmessage = =>
|
||||
fn() while fn = @pendingNextTickFns.shift()
|
||||
|
||||
@pendingNextTickFns.push(fn)
|
||||
@messageChannel.port2.postMessage(0)
|
||||
|
||||
Reference in New Issue
Block a user