TextDocument

open class TextDocument(initialText: String) : SealedTextDocument

The HistoryDocument used by TextArea. The document is stored as a List of String, where each String must NOT include new line character.

An empty document is NOT an empty list. It is a list containing a single blank string. You may safely assume that lines is never an empty list.

Changes related to a TextDocument are subclasses of TextChange. There are only 2 DeleteText and InsertText. Replacements are comprised of a DeleteText followed by an InsertText within a single Batch. As such, undo/redo will never split them; they appear to be atomic.

NOTE. Changes to the caret/anchor positions of a TextArea are not part of a TextDocument, they are part of the TextArea. Therefore, you cannot undo/redo changes to the caret/anchor positions.

Inheritors

Constructors

Link copied to clipboard
constructor(initialText: String)

Properties

Link copied to clipboard

The text is held as an array of lines. This makes editing the text much more efficient than using one huge String (with new-line characters). New line characters are NOT included in the list elements.

Link copied to clipboard
Link copied to clipboard

TextDocument does NOT store the document as a String, it is stored as a list of strings where each item in the list does NOT contain a new line character.

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard

Returns a TextChange object, but does not apply that change. Useful for batching multiple changes together so that undo/redo treats them as a single step.

Link copied to clipboard
fun delete(from: TextPosition, to: TextPosition, allowMerge: Boolean = false)
Link copied to clipboard

Returns a TextChange object, but does not apply that change. Useful for batching multiple changes together so that undo/redo treats them as a single step.

Link copied to clipboard
fun insert(from: TextPosition, toInsert: String, allowMerge: Boolean = false)
fun insert(from: TextPosition, toInsert: List<String>, allowMerge: Boolean = false)
Link copied to clipboard
fun insertChange(from: TextPosition, toInsert: String, allowMerge: Boolean): InsertText?
fun insertChange(from: TextPosition, toInsert: List<String>, allowMerge: Boolean): InsertText?

Returns a TextChange object, but does not apply that change. Useful for batching multiple changes together so that undo/redo treats them as a single step.

Link copied to clipboard
Link copied to clipboard
fun setText(text: String)
Link copied to clipboard
Link copied to clipboard

If pos is a valid TextPosition for this document, it is returned (unchanged). Otherwise, a new TextPosition is returned, which is valid. The row is in the range :