public final class InlineStyles

  1. Object
  2. InlineStyles
The per character inline style model for the pure rich text editor. It keeps one TextStyle reference for every character in the document, kept in lockstep with the text through #applyEdit. Runs of identical style are coalesced only at render time, which keeps edits simple and correct at the cost of one reference per character (rich documents are small enough for this to be a non issue).

Nested types

interface InlineStyles.StyleTransformA transform applied to a character’s style, used to toggle bold, set a color, etc.
interface InlineStyles.StylePredicateA predicate over a style, used by #allInRange.

Constructors

public InlineStyles(int length)Creates a model of the given length, all default style.

Methods

public void reset(int length)Resets the model to the given length, all default style.
public int length()Returns the number of characters covered.
public TextStyle styleAt(int index)Returns the style of the character at index, or the default style out of range.
public void applyEdit(int start, int removedLen, int insertedLen, TextStyle style)Keeps the model in sync with a text replacement: removes removedLen styles at start and inserts insertedLen copies of style.
public void setAt(int index, TextStyle style)Sets the style of a single character.
public void transformRange(int start, int end, InlineStyles.StyleTransform t)Applies a transform to every character’s style in [start, end).
public boolean allInRange(int start, int end, InlineStyles.StylePredicate p)True when every character in [start, end) satisfies the predicate.

Inherited methods

Constructor details

InlineStyles

public InlineStyles(int length)
Creates a model of the given length, all default style.

Method details

reset

public void reset(int length)
Resets the model to the given length, all default style.

length

public int length()
Returns the number of characters covered.

styleAt

public TextStyle styleAt(int index)
Returns the style of the character at index, or the default style out of range.

applyEdit

public void applyEdit(int start, int removedLen, int insertedLen, TextStyle style)
Keeps the model in sync with a text replacement: removes removedLen styles at start and inserts insertedLen copies of style.

Parameters

start int
the offset of the edit
removedLen int
number of characters removed
insertedLen int
number of characters inserted
style TextStyle
the style applied to the inserted characters

setAt

public void setAt(int index, TextStyle style)
Sets the style of a single character.

transformRange

public void transformRange(int start, int end, InlineStyles.StyleTransform t)
Applies a transform to every character’s style in [start, end).

allInRange

public boolean allInRange(int start, int end, InlineStyles.StylePredicate p)
True when every character in [start, end) satisfies the predicate. An empty range checks the character just before the caret (the style typing would continue with).