Closed as-cii closed 5 years ago
Thanks for reviewing this, @probablycorey! ✨
- cursors are going to be treated as zero length selections
Correct!
- each user will have a selection set. So an individual user will create an initial selection set and then replace that selection set when the cursor or selection changes.
This is correct too. A single user may also have multiple selection sets in case there are multiple editors for the same buffer, such as when splitting an editor.
- when a selection changes from a user, I'll query the buffer for all selections (not just for that user) and update all of them in the editor.
I have just changed this because wasm-bindgen complains when re-entrantly calling from JavaScript into Rust. The callback passed to Buffer.prototype.onChange
will now be called with an object describing both text changes and the final state of selections, if either one of those changes after applying operations.
This pull request introduces new APIs for creating, replacing and removing selections. Examples can be found in the documentation or in tests:
Buffer.prototype.addSelectionSet(ranges)
. This method takes an array of ranges representing the initial selections of the set and returns a tuple containing the newly-created set id (that you can use to manipulate the set later on) and an operation that can be broadcasted to other replicas.Buffer.prototype.replaceSelectionSet(setId, ranges)
. This method takes the id of a set that was previously created and an array of ranges to replace the existing ranges in the set. It returns an operation that can be broadcasted to other replicas.Buffer.prototype.removeSelectionSet(setId)
. This method takes the id of a set that was previously created and deletes it. It return an operation that can be broadcasted to other replicas.Buffer.prototype.getSelections()
. This method returns all the selections that are currently available on the Buffer in the following form:Buffer.prototype.onChange(listener)
. This method has been changed to also report all the selection ranges belonging to a buffer when operations are applied.