an-cabal / an-rope

an rope data structure
https://docs.rs/an-rope
MIT License
11 stars 2 forks source link

Add a finger or cursor to Rope #40

Open hawkw opened 7 years ago

hawkw commented 7 years ago

Since the primary use-case for our Rope is text editing, we ought to provide some kind of cursor/finger/zipper for our Rope, a structure that optimises edit speeds around a particular location. In a text editor, a majority of editing takes place around a cursor position in the document, and if we provide a cursor over a Rope, we can use it to make a majority of Rope operations much faster.

hawkw commented 7 years ago

Some references:

twisted-pear commented 7 years ago

somewhat related to #31, would it make sense to have the rope split a node on a newline? would make lines() easier and probably also speed up edits like inserting/removing a line

hawkw commented 7 years ago

@twisted-pear: yeah; see also #32. @cjm00 and i have definitely at least discussed doing that in the past. might make a lot of sense for our use case. this also has the rather nice side benefit of letting branches could also store their line count, making line counting nicely fast

hawkw commented 7 years ago

I suspect we could probably rewrite a lot of our messy iterator & slice code to use a base cursor structure and then add different behaviours to it with traits...