-
Notifications
You must be signed in to change notification settings - Fork 71
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.onDidChangemethod 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
onDidChangeandonDidChangeText; they are now identical. Listeners get called once per transaction.I'm ensuring backwards-compatibility for existing users of
onDidChangeby synthesizing the old event propertiesoldRange,newRange,oldTextandnewText. For example, if two separate changes occur in a transaction,oldRangewill be the smallest possibleRangethat encompasses both of the changes.The
oldTextandnewTextproperties are now deprecated. Callers who are interested in the text that was inserted or removed should use thechangesproperty to examine individual changes./cc @nathansobo