public final class InlineStyles
- Object
- 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.StyleTransform | A transform applied to a character’s style, used to toggle bold, set a color, etc. |
interface InlineStyles.StylePredicate | A 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
startint- the offset of the edit
removedLenint- number of characters removed
insertedLenint- number of characters inserted
styleTextStyle- 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).