-
Notifications
You must be signed in to change notification settings - Fork 73
Replace onDidChange with an enhanced version of onDidChangeText #273
Conversation
@emitter.on 'did-change-text', callback | ||
|
||
# Public: This is now identical to {onDidChange}. | ||
onDidChangeText: (callback) -> @onDidChange(callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not worth the hassle of deprecating it? Probably not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should, but I thought we should do that in a second pass, after we remove all of our own uses of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with oldText
and newText
. I want to deprecate them soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Background
The
TextBuffer.onDidChange
method has long been a source of performance problems because it causes its callback to be called for each individual change that happens to aTextBuffer
. This behavior makes it very expensive to make a series of small changes to a buffer with any change observers. This is important for multi-cursor editing, and it also has shaped other decisions about how to mutate buffers, encouraging preprocessing strings before inserting them into text buffers rather doing the preprocessing in the buffer itself.A while ago, we added a more efficient way of observing changes to buffers -
TextBuffer.onDidChangeText
. Callbacks passed to this method get called only once per transaction, and are passed an array of the consolidated changes that occurred in that transaction.Solution
This PR unifies
onDidChange
andonDidChangeText
; they are now identical. Listeners get called once per transaction.I'm ensuring backwards-compatibility for existing users of
onDidChange
by synthesizing the old event propertiesoldRange
,newRange
,oldText
andnewText
. For example, if two separate changes occur in a transaction,oldRange
will be the smallest possibleRange
that encompasses both of the changes.The
oldText
andnewText
properties are now deprecated. Callers who are interested in the text that was inserted or removed should use thechanges
property to examine individual changes./cc @nathansobo