Fix text editing for layouts which contain inline boxes #299
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes #296, since they both touch the selection-drawing code.
There were a couple issues preventing text cursor positioning and selection from working on lines with inline boxes:
Cluster::from_point
andCluster::from_byte_index
were setting therun_index
in their cluster paths to the index of the nth line item that is a run. It should be set to the nth line item, regardless of whether the previous items are inline boxes.Cluster::from_point
andSelection::geometry_with
were ignoring inline boxes when accumulating the lines' advance widths.It's not perfect yet. Cursor affinity should take inline boxes into account, but since we could have multiple inline boxes in a row, or inline boxes next to soft line breaks, the cursor affinity will need to be an index and not just an upstream/downstream state (how do other APIs handle this?) That's a much bigger undertaking for a later time.
There was also a discrepancy between the documentation for inline boxes and the implementation--
InlineBox::index
is documented as the byte index to insert the box at, whereas the shaping code treated it as a character index. I've changed the shaping code to treat it as a byte index, but I could change the documentation instead.