Issue
Is it possible to apply automatic HTML formatting to text as it's typed into a JavaFX HTMLEditor
?
Previously I achieved what I wanted via the RichTextFx class, but I wanted to see if it's possible via HTMLEditor
as this is now standard to JavaFX.
The only way I can see so far is to get the HTML text, strip it of its tags, then apply my own tag formatting, then set the HTML text contents again. Although inefficient this would probably work for what I want, but having tried it the editor loses focus and requestFocus()
doesn't focus, and even if it did I think I'd have to set the cursor position.
Solution
I suspect it is possible to do it as you describe, though it will be inefficient in the ways you have already identified.
Perhaps a better solution, assuming RichTextFX isn't an option, would be to roll your own solution using TextFlow and multiple Text nodes.
https://openjfx.io/javadoc/11/javafx.graphics/javafx/scene/text/TextFlow.html
That is essentially what RichTextFX is doing.
Answered By - swpalmer