y-crdt / y-crdt

Rust port of Yjs
https://docs.rs/yrs/
Other
1.46k stars 83 forks source link

Use Rust Range for describing range operations #343

Open Horusiath opened 11 months ago

Horusiath commented 11 months ago

Atm. we're using a 4-param way of describing ranges (see: Array::quote, Array::move_range_to). I find them pretty unintuitive myself. Given that Rust has excellent support for ranges of all kinds, including detailed bounds definitions, we should use them instead.

Current API: array.move_range_to(txn, 1, Assoc::Right, 3, Assoc::Left, 0) Proposed one: array.move_range_to(txn, 1..3, 0)

This ofc makes it kinda harder when it comes to definition of "stickyness", but think that we could map this onto inclusive/exclusive bounds anyway ie.

  1. ..3 which means, from start of the collection till the 3 index exclusive means that range should include concurrent inserts that could happen between indexes 2 and 3, but not the index 3 itself.
  2. ..=2 (index number 2 inclusive) means that we stick to the 2 instead - any concurrent inserts between 2 and 3 will not be included into this range.

Rich text editors usually don't define left/right cursor associativity anyway.

Horusiath commented 10 months ago

This has been done for quotations as part of #334. I'll update move_range in the future to reflect that - this is not very important atm as move_range is an experimental feature.