Open XJianfei opened 1 month ago
I think if you try adding some text, it will be more clear.
state: <p>ABC</p>Test
A lineCount=2
state: <p>ABC</p>Test1<br>Test2
B lineCount=3
Also, if you set this HTML to add a RichTextState <p>ABC</p><br>
and then try to change the RichTextState back to HTML you will get the exact same HTML data <p>ABC</p><br>.
The second line is coming from the closing of the p tag, and the third line is coming from the br tag. That's the exact result that you will get if you try that HTML in the browser.
I try the code as below, and after type 'ABC
It show 'state lineCount=2', but 'state2 lineCount=3',
state2 is setHtml from state.toHtml
val state = rememberRichTextState()
val textMeasurer = rememberTextMeasurer()
BasicRichTextEditor(
state = state,
onTextLayout = { layout ->
println("html: ${state.toHtml()}")
var annotatedString = state.annotatedString
val textStyle = TextStyle()
var textLayout = textMeasurer.measure(
text = annotatedString,
style = textStyle,
constraints = Constraints(0, 1000, 0, Constraints.Infinity),
overflow = TextOverflow.Clip,
)
println("state lineCount=${textLayout.lineCount}, ${layout.lineCount}")
val state2 = RichTextState()
state2.setHtml(state.toHtml())
annotatedString = state2.annotatedString
textLayout = textMeasurer.measure(
text = annotatedString,
style = textStyle,
constraints = Constraints(0, 1000, 0, Constraints.Infinity),
overflow = TextOverflow.Clip,
)
println("state2 lineCount=${textLayout.lineCount}")
},
)
And after type 'AB
After fixed #355 , the lineCount still wrong. The code like this:
The output is