Closed balthild closed 1 month ago
There's no built-in functionality for this, but it's not particularly hard to implement yourself based on the edits made.
(The reason it's not built-in to Ropey is because there's no "right" way to do it, as you'll likely discover if you take a crack at implementing it yourself. It depends on how you model cursors, among other things. So it seemed best to leave that up to the application rather than forcing a particular model. Omitting it also keeps Ropey more focused in its scope: it's just about representing the text itself, not any metadata about it.)
Thanks for the explanation. Could you give me some ideas how to implement it? I'm not familiar with rope data structure and the only way I can think of is adding/subtracting the index according to inserted text's position and length. I'm not sure if this is correct for rope because it seems like a way for normal text buffers (like Vec<u8>
).
Sure, I have a simple implementation in my toy text editor that you can take a look at:
You can also look at Helix for a more sophisticated implementation. I think this is the code:
Thank you!
For example, yrs (another Rust CRDT library) provides
StickyIndex
API for cursor positioning. Is there a way to do similar things with ropey?