linebender / parley

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

Parley cannot compute caret geometry if layout text is empty #135

Open nicoburns opened 1 month ago

nicoburns commented 1 month ago

The following screen capture shows the issue. This is using a PlainEditor and drawing the selection/caret as in the vello_editor example. Note that there is initially no caret even though the input is focssed. The caret shows once some text has been typed in the field and disappears again when the text is deleted.

https://github.com/user-attachments/assets/a3881822-e5fc-48c9-aff9-5d25b6481bbf

xorgy commented 1 month ago

Yeah, this is similar I think to the issue of caret position downstream of a hard line break.

dfrg commented 1 month ago

This is actually because the layout is empty therefore we don’t do any font selection and have no metrics from which to generate cursor geometry. My upcoming code has a hack to address this by forcing layout of a single space (which used to be there but was removed at some point). There’s definitely a better way to do this but I plan to defer that to the larger refactor.

nicoburns commented 1 month ago

Ah yes, I removed that in #67 because, well, it seemed like a hack (and improvements in #67 meant that it would no longer panic when the string was empty). I guess the space hack will work but we'll need to keep track that we're in that "mode" so that we don't allow the space to be selected, etc.

There is actually another "mode" that I want which could probably work similarly: placeholder text. Which I am imagining working by having a second text string and set of styles that would be used as a fallback when the main string is empty.