atom-archive / xray

An experimental next-generation Electron-based text editor
MIT License
8.48k stars 235 forks source link

Introduce Selections #170

Closed as-cii closed 5 years ago

as-cii commented 5 years ago

This pull request introduces new APIs for creating, replacing and removing selections. Examples can be found in the documentation or in tests:

as-cii commented 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.