mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-15 03:04:37 +03:00
Batch multiple view updates with Editor::batchUpdates
This commit is contained in:
parent
fe6a007774
commit
ddc677fb30
@ -15,7 +15,8 @@ EditorCompont = React.createClass
|
||||
pendingScrollTop: null
|
||||
pendingScrollLeft: null
|
||||
selectOnMouseMove: false
|
||||
|
||||
batchingUpdates: false
|
||||
updateRequested: false
|
||||
|
||||
render: ->
|
||||
{focused, fontSize, lineHeight, fontFamily, showIndentGuide} = @state
|
||||
@ -74,6 +75,8 @@ EditorCompont = React.createClass
|
||||
|
||||
observeEditor: ->
|
||||
{editor} = @props
|
||||
@subscribe editor, 'batched-updates-started', @onBatchedUpdatesStarted
|
||||
@subscribe editor, 'batched-updates-ended', @onBatchedUpdatesEnded
|
||||
@subscribe editor, 'screen-lines-changed', @onScreenLinesChanged
|
||||
@subscribe editor, 'selection-screen-range-changed', @requestUpdate
|
||||
@subscribe editor, 'selection-added', @onSelectionAdded
|
||||
@ -258,6 +261,16 @@ EditorCompont = React.createClass
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
onBatchedUpdatesStarted: ->
|
||||
@batchingUpdates = true
|
||||
|
||||
onBatchedUpdatesEnded: ->
|
||||
updateRequested = @updateRequested
|
||||
@updateRequested = false
|
||||
@batchingUpdates = false
|
||||
if updateRequested
|
||||
@forceUpdate()
|
||||
|
||||
onScreenLinesChanged: ({start, end}) ->
|
||||
{editor} = @props
|
||||
@requestUpdate() if editor.intersectsVisibleRowRange(start, end + 1) # TODO: Use closed-open intervals for change events
|
||||
@ -284,7 +297,10 @@ EditorCompont = React.createClass
|
||||
clearVisibleRowOverridesAfterDelay: null
|
||||
|
||||
requestUpdate: ->
|
||||
@forceUpdate()
|
||||
if @batchingUpdates
|
||||
@updateRequested = true
|
||||
else
|
||||
@forceUpdate()
|
||||
|
||||
updateModelDimensions: ->
|
||||
@refs.scrollView.updateModelDimensions()
|
||||
|
@ -1781,7 +1781,9 @@ class Editor extends Model
|
||||
# execution and revert any changes performed up to the abortion.
|
||||
#
|
||||
# fn - A {Function} to call inside the transaction.
|
||||
transact: (fn) -> @buffer.transact(fn)
|
||||
transact: (fn) ->
|
||||
@batchUpdates =>
|
||||
@buffer.transact(fn)
|
||||
|
||||
# Public: Start an open-ended transaction.
|
||||
#
|
||||
@ -1801,6 +1803,11 @@ class Editor extends Model
|
||||
# within the transaction.
|
||||
abortTransaction: -> @buffer.abortTransaction()
|
||||
|
||||
batchUpdates: (fn) ->
|
||||
@emit 'batched-updates-started'
|
||||
fn()
|
||||
@emit 'batched-updates-ended'
|
||||
|
||||
inspect: ->
|
||||
"<Editor #{@id}>"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user