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:
Nathan Sobo
2012-11-14 13:57:27 -07:00
parent 5a1a1da386
commit a6e928d85a
2 changed files with 12 additions and 2 deletions

View File

@@ -734,7 +734,7 @@ class Editor extends View
requestDisplayUpdate: ()->
return if @pendingDisplayUpdate
@pendingDisplayUpdate = true
webkitRequestAnimationFrame =>
_.nextTick =>
@updateDisplay()
@pendingDisplayUpdate = false

View File

@@ -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)