DocumentEditScope

A mutable view of a text document handed to DocumentState.edit. Calls made on it inside the edit { } block are applied to the document as one compound change, so the field observes a single settled edit rather than each intermediate step.

Offsets address the buffer's current content and shift as edits are applied, exactly as they do against the underlying document: an insert at offset 2 makes a following delete at offset 2 operate on the text after the insertion.

Every call that writes text has an overload taking an AttributeSet, the attributes the written run carries - a bold word, a colored span, a link. They reach a document that models attributes: the styled document a TextPane renders, or the one an editable EditorPane's kit builds. A document that holds characters alone - the plain text a TextField or a TextArea renders - ignores them, so the text arrives unstyled rather than refused.

See also

Properties

Link copied to clipboard
val length: Int

The length of the buffered content.

Functions

Link copied to clipboard
fun append(text: @Nls CharSequence)

Appends text to the end of the buffer.

fun append(text: @Nls CharSequence, attributes: AttributeSet)

Appends text carrying attributes to the end of the buffer.

Link copied to clipboard
fun delete(start: Int, end: Int)

Deletes the characters in [start, end).

Link copied to clipboard
fun insert(offset: Int, text: @Nls CharSequence)

Inserts text at offset, shifting following content right.

fun insert(offset: Int, text: @Nls CharSequence, attributes: AttributeSet)

Inserts text carrying attributes at offset, shifting following content right.

Link copied to clipboard

Places the caret at the end of the buffer as it stands once the block completes.

Link copied to clipboard
fun replace(start: Int, end: Int, text: @Nls CharSequence)

Replaces the characters in [start, end) with text.

fun replace(start: Int, end: Int, text: @Nls CharSequence, attributes: AttributeSet)

Replaces the characters in [start, end) with text carrying attributes.

Link copied to clipboard
fun selectAll()

Selects the whole buffer as it stands once the block completes.

Link copied to clipboard
fun setText(text: @Nls CharSequence)

Replaces the whole buffer with text.

fun setText(text: @Nls CharSequence, attributes: AttributeSet)

Replaces the whole buffer with text carrying attributes.