diff --git a/sources/Text/MutableText.uc b/sources/Text/MutableText.uc index b12bfd8..3b4c76a 100644 --- a/sources/Text/MutableText.uc +++ b/sources/Text/MutableText.uc @@ -371,6 +371,21 @@ public final function MutableText Replace( return self; } +/** + * Sets `newFormatting` for every non-formatted character in the caller `Text`. + * + * @param newFormatting Formatting to use for all non-formatted character in + * the caller `Text`. If `newFormatting` is not colored itself - + * method does nothing. + * @return Returns caller `MutableText`, to allow for method chaining. + */ +public final function MutableText ChangeDefaultFormatting( + Formatting newFormatting) +{ + _changeDefaultFormatting(newFormatting); + return self; +} + /** * Changes formatting for characters with indices in range, specified as * `[startIndex; startIndex + maxLength - 1]` to `newFormatting` parameter. diff --git a/sources/Text/Tests/TEST_Text.uc b/sources/Text/Tests/TEST_Text.uc index d6e2f25..898df44 100644 Binary files a/sources/Text/Tests/TEST_Text.uc and b/sources/Text/Tests/TEST_Text.uc differ diff --git a/sources/Text/Text.uc b/sources/Text/Text.uc index 422545c..31d5747 100644 --- a/sources/Text/Text.uc +++ b/sources/Text/Text.uc @@ -982,6 +982,49 @@ protected final function Text DropCodePoints() { return self; } +/** + * Sets `newFormatting` for every non-formatted character in the caller `Text`. + * Allows to create mutable child classes. + * + * @param newFormatting Formatting to use for all non-formatted character in + * the caller `Text`. If `newFormatting` is not colored itself - + * method does nothing. + * @return Returns caller `Text`, to allow for method chaining. + */ +protected final function Text _changeDefaultFormatting(Formatting newFormatting) +{ + local int i; + local FormattingChunk newFormattingChunk; + local array newFormattingChunks; + if (!newFormatting.isColored) { + return self; + } + newFormattingChunk.formatting = newFormatting; + if ( formattingChunks.length <= 0 + || formattingChunks[0].startIndex > 0) + { + newFormattingChunks[0] = newFormattingChunk; + } + while (i < formattingChunks.length) + { + if (formattingChunks[i].formatting.isColored) + { + newFormattingChunks[newFormattingChunks.length] = + formattingChunks[i]; + } + else + { + newFormattingChunk.startIndex = formattingChunks[i].startIndex; + newFormattingChunks[newFormattingChunks.length] = + newFormattingChunk; + } + i += 1; + } + formattingChunks = newFormattingChunks; + NormalizeFormatting(); + return self; +} + /** * Sets formatting for the next code point(s) to be added by * `AppendCodePoint()` / `AppendManyCodePoints()`.