This class is a mutable extension of MConstText. It has methods for inserting, appending, replacing, and removing styled text. Additionally, it has methods for modifying paragraph and character styles.
Styled characters (from another MConstText
instance) added to the text retain their original character styles. The style of plain characters (specified as a char
or char[]
) is always specified explicitly when they are added to the text. MText does not do character style "propagation", where unstyled characters take on the style of previous characters. Clients can implement this behavior by specifying the styles to propagate.
When unstyled characters are added to the text, their paragraph style is the paragraph style in effect immediately after the last new character. If the characters contain paragraph separators, then every new paragraph will have the same paragraph style. When styled characters are added to the text, their resulting paragraph style is determined by the following rule:
The paragraph styles in the new text become the paragraph styles in the target text, with the exception of the last paragraph in the new text, which takes on the paragraph style in effect immediately after the inserted text. If the new text is added at the end of the target text, the new text's paragraph styles take effect in any paragraph affected by the addition.
For example, suppose there is a single paragraph of text with style 'A', delimited with a paragraph separator 'P':
AAAAAAP
Suppose the following styled paragraphs are inserted into the above text after the fourth character:
BBBBPCCCPDDD
Then the original paragraph style of each character is:
AAAABBBBPCCCPDDDAAP
The resulting paragraph styles are:
BBBBBBBBPCCCPAAAAAP
Similarly, if characters are deleted, the paragraph style immediately after the deletion takes effect on the paragraph containing the deletion. So, if characters 4-16 were deleted in the example above, the paragraph styles would be:
AAAAAAP
This paragraph-style propagation policy is sometimes referred to as
following styles win, since styles at the end of the paragraph become the style for the entire paragraph.
This class can accumulate a damaged range - an interval in which characters, character styles, or paragraph styles have changed. This is useful for clients such as text editors which reformat and draw text after changes. Usually the damaged range is exactly the range of characters operated upon; however, larger ranges may be damaged if paragraph styles change.
@see StyleModifier