From b2d3d05790913d2525b74b1ce30d6e7e1f7aa51b Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Fri, 17 Jun 2022 20:26:11 +0700 Subject: [PATCH] Add `ChangeDefaultFormatting()` to `MutableText` --- sources/Text/MutableText.uc | 15 +++++++++++ sources/Text/Tests/TEST_Text.uc | Bin 122570 -> 126230 bytes sources/Text/Text.uc | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) 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 d6e2f25a988e60a7f3afe360858cab66d7046deb..898df4491126e5fe78903595c16b23883fc23277 100644 GIT binary patch delta 796 zcmZ{i&rcIk5XWai%r@GVLO>`|yM!k80HLCuP!6OgwJC`)-qZpsHk58tib%{B4&FSF z_!8%$#>5-eE@=>oMX61Vh6^Ufka%e0U!WI`{+PFIwI-UE_haYHeDj^p+uc{ngU`zH zI_|GJf}p_-h`>C=AVs4u@C1Ed#Ze5>w*vNw9eX?Jr_r~$FN5_cU2DUm< zGWhV&1lP}t;=Qhx0Z?hp#D4l(zyL+EIF2D&%iS{CU6XK=J;!01-A{qa>n)yfdcA<|{#s}OqLAV= zmD6;dgD}Z^jAs(G`|rKlk z;DEz?V-3pWu~S?~cTngZ21gjZRaM&!xC1`cjW#))V@3J0DUL6)#j;i{5w|5=pyX{FOscSw*6mGFzEVAT%_ 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()`.