linebender / parley

Rich text layout library
Apache License 2.0
229 stars 28 forks source link

PlainEditor: Add byte selection and navigation operations. #146

Closed xorgy closed 3 weeks ago

xorgy commented 3 weeks ago
xorgy commented 3 weeks ago

I promise that if you file an issue, I will write tests at some point for PlainEditor; if for no other reason than to catch issues in upcoming Cursor changes.

mwcampbell commented 3 weeks ago

A bit late, but LGTM.

mwcampbell commented 3 weeks ago

I forgot about affinity semantics. With AccessKit, the client (e.g. screen reader) can theoretically specify the affinity at both ends when setting the selection, though I don't think any of the platform accessibility APIs actually allow that.

xorgy commented 3 weeks ago

@DJMcNab @mwcampbell Yeah, this is a bit of a mess right now with how Cursor currently works, I intend to add some fns to Cursor that make it easier to model ‘insertion’ and other behaviors, but the fundamental issue is that Cursors can't be constructed where index = buffer.len(), which makes all of these behaviors highly conditional (because inserting at the end of the buffer always has to be len() - 1 with Downstream affinity).

xorgy commented 3 weeks ago

If we make a Cursor type that is based on an insertion index first, like the Parley 0.1 Cursor, then all these behaviors become much easier (because we can just always have Upstream affinity when inserting, and the neutral empty cursor at index = 0 suddenly makes sense)