StyledTextArea

A TextArea with the ability to style the text (in a limited way). This is designed as a code editor, where keywords, constants, Strings etc. can be displayed using different colors.

It also allows portions of the text to be highlighted (e.g. for text which matches a search string). The highlighting is limited - the line height is assumed to be the same for ALL text styles.

NOTE. Theming this is a bit weird (you may even consider it buggy). The font is stylable in the same way as TextArea, however, this is only used to calculate caret positions, line heights etc., and is NOT used when drawing the text. Drawing the text uses the styles of the Text nodes (which may be styled differently). So if they don't match, the caret position won't match the rendered text. Ooops!

So if the styled Text use a different font to StyledTextArea's font, they must all be the same size (i.e. a fixed width font at the same point size).

At present StyledTextArea is not suitable for editing rich text for two reasons :

  1. All text must be the same size

  2. The StyledTextDocument.ranges are not part of the history mechanism, so there is no way to add/remove ranges which is compatible with undo/redo.

Constructors

Link copied to clipboard
constructor(initialText: String)
constructor(stringProperty: StringProperty)
constructor(document: StyledTextDocument)

Functions

Link copied to clipboard
fun setSimpleStyledText(str: String, styles: Map<Char, Highlight>, terminators: Map<Char, Char> = emptyMap())

Parses str, looking for style markings, which are single characters from the keys of styles. The style markings are removed and the remainder is used as the document's text.