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