mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Add 'stopped-changing' event to buffer. Fires 300ms after last change.
This will be used by the status bar and other expensive code that needs to respond to the buffer changing, but that we don't want running on every single keystroke when the user is typing quickly.
This commit is contained in:
parent
632bba5609
commit
4a84c5f8f9
@ -727,3 +727,23 @@ describe 'Buffer', ->
|
||||
expect(buffer.isEmpty()).toBeFalsy()
|
||||
buffer.setText('\n')
|
||||
expect(buffer.isEmpty()).toBeFalsy()
|
||||
|
||||
describe "stopped-changing event", ->
|
||||
it "fires 'stoppedChangingDelay' ms after the last buffer change", ->
|
||||
delay = buffer.stoppedChangingDelay
|
||||
stoppedChangingHandler = jasmine.createSpy("stoppedChangingHandler")
|
||||
buffer.on 'stopped-changing', stoppedChangingHandler
|
||||
|
||||
buffer.insert([0, 0], 'a')
|
||||
expect(stoppedChangingHandler).not.toHaveBeenCalled()
|
||||
|
||||
advanceClock(delay / 2)
|
||||
|
||||
buffer.insert([0, 0], 'b')
|
||||
expect(stoppedChangingHandler).not.toHaveBeenCalled()
|
||||
|
||||
advanceClock(delay / 2)
|
||||
expect(stoppedChangingHandler).not.toHaveBeenCalled()
|
||||
|
||||
advanceClock(delay / 2)
|
||||
expect(stoppedChangingHandler).toHaveBeenCalled()
|
||||
|
@ -41,6 +41,8 @@ class BufferChangeOperation
|
||||
|
||||
event = { oldRange, newRange, oldText, newText }
|
||||
@buffer.trigger 'change', event
|
||||
@buffer.scheduleStoppedChangingEvent()
|
||||
|
||||
anchor.handleBufferChange(event) for anchor in @buffer.getAnchors()
|
||||
@buffer.trigger 'update-anchors-after-change'
|
||||
newRange
|
||||
|
@ -13,6 +13,8 @@ Git = require 'git'
|
||||
module.exports =
|
||||
class Buffer
|
||||
@idCounter = 1
|
||||
stoppedChangingDelay: 300
|
||||
stoppedChangingTimeout: null
|
||||
undoManager: null
|
||||
cachedDiskContents: null
|
||||
cachedMemoryContents: null
|
||||
@ -378,4 +380,11 @@ class Buffer
|
||||
if @git?.checkoutHead(path)
|
||||
@trigger 'git-status-change'
|
||||
|
||||
scheduleStoppedChangingEvent: ->
|
||||
clearTimeout(@stoppedChangingTimeout) if @stoppedChangingTimeout
|
||||
stoppedChangingCallback = =>
|
||||
@stoppedChangingTimeout = null
|
||||
@trigger 'stopped-changing'
|
||||
@stoppedChangingTimeout = setTimeout(stoppedChangingCallback, @stoppedChangingDelay)
|
||||
|
||||
_.extend(Buffer.prototype, EventEmitter)
|
||||
|
Loading…
Reference in New Issue
Block a user