Fix block styling to support empty lines in editor #13
Labels
architectural-decision
For if we need to make a decision before diving in to writing code
difficult
An issue where the code required to solve it is difficult to write.
textkit
Requires interacting with Apple's TextKit framework
Background
TextKit 1, which Lexical uses, doesn't really support block level elements. Margins/padding are applied at a paragraph level, where paragraph is defined as any text separated by newlines.
In Lexical, we wanted to allow nodes to behave like block level elements like they do on the web. For example, our Code node has some top/bottom margin and some padding in order to draw its bordered box.
The way Lexical iOS accomplishes this is by taking the node that is calling for top/bottom margin/padding, and applying the top margin to the first paragraph within that node, and the bottom margin to the last paragraph within that node.
Issues
I wrote the block level styling system as part of the Feed Inlines project, which uses read-only Lexical. I'm now making sure it works well with editable Lexical too.
There are two main issues that need addressing:
Metric updating
There are/were two problems here:
Last line drawing
As well as the last line being excluded when calculating which paragraphs need top/bottom margin (as mentioned above), we also have the issue of how to actually apply any form of styling to the last line at all. As mentioned, it does not correspond to any range in the backing attributed string, so where do we apply attributes?
The last line is handled as a special case by TextKit, and is known as the extraLineFragment. TextKit places and styles it (as far as I can see) according to the last character on the previous line's attributes.
Status
I have written code (as yet unpublished) to fix the first part of this. I'm working on the
extraLineFragment
support, and am having some trouble getting it to work reliably.The text was updated successfully, but these errors were encountered: