Using egui and TreeSitter - a problem of byte- and character indices #7301
-
|
Hi, I'm using egui for a text editor for my music coding language (which is LISP-like in syntax). I wanted to make the editor more flexible, so instead of ad-hoc solutions for finding s-expressions etc, I created a TreeSitter grammar to navigate the code. But, alas, TreeSitter gives you positions exclusively in bytes, while egui's text cursors all work with character indices ... There's a helper function Is there a good way to bring the two together, or would there be any alternatives to TreeSitter? Best, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
To answer my own question, using a text rope (i.e. the I replaced the |
Beta Was this translation helpful? Give feedback.
To answer my own question, using a text rope (i.e. the
ropeycrate) helps translating between the two.I replaced the
TextBufferin myTextEditwidget implementation (I'm using a custom one) withropey::Ropeand it facilitates working with the byte positions provided byTreeSitter