From 4c378f7cd9d08a513dd056d2d261315ab93a4c0a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 29 Sep 2024 12:17:47 +0200 Subject: [PATCH] Fixed formatting codes at the start of strings not being added to the AllCodes collection Closes #26 --- CHANGELOG.md | 4 ++++ MLEM/Formatting/TextFormatter.cs | 4 +++- Tests/FontTests.cs | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 056e072..4cab477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ Jump to version: ## 7.1.2 (In Development) +### MLEM +Fixes +- Fixed formatting codes at the start of strings not being added to the AllCodes collection + ### MLEM.Ui Additions - Added Panel.IsVisible method to check if a child element is visible diff --git a/MLEM/Formatting/TextFormatter.cs b/MLEM/Formatting/TextFormatter.cs index 3f0a16a..a5220d7 100644 --- a/MLEM/Formatting/TextFormatter.cs +++ b/MLEM/Formatting/TextFormatter.cs @@ -160,8 +160,10 @@ public TokenizedString Tokenize(GenericFont font, string s, TextAlignment alignm var allCodes = new List(); // add the formatting code right at the start of the string var firstCode = this.GetNextCode(s, 0, 0); - if (firstCode != null) + if (firstCode != null) { + allCodes.Add(firstCode); applied.Add(firstCode); + } var index = 0; var rawIndex = 0; while (rawIndex < s.Length) { diff --git a/Tests/FontTests.cs b/Tests/FontTests.cs index 68decdd..72b171f 100644 --- a/Tests/FontTests.cs +++ b/Tests/FontTests.cs @@ -118,11 +118,11 @@ public void TestMacros() { [Test] public void TestFormatting() { this.formatter.AddImage("Test", new TextureRegion((Texture2D) null, 0, 8, 24, 24)); - const string strg = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; + const string strg = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; var ret = this.formatter.Tokenize(this.font, strg); - Assert.AreEqual(ret.Tokens.Length, 13); + Assert.AreEqual(ret.Tokens.Length, 16); Assert.AreEqual(ret.DisplayString, "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."); - Assert.AreEqual(ret.AllCodes.Length, 12); + Assert.AreEqual(ret.AllCodes.Length, 16); } [Test]