Skip to content

Commit

Permalink
Fixed formatting codes at the start of strings not being added to the…
Browse files Browse the repository at this point in the history
… AllCodes collection

Closes #26
  • Loading branch information
Ellpeck committed Sep 29, 2024
1 parent f35730e commit 4c378f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion MLEM/Formatting/TextFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ public TokenizedString Tokenize(GenericFont font, string s, TextAlignment alignm
var allCodes = new List<Code>();
// 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) {
Expand Down
6 changes: 3 additions & 3 deletions Tests/FontTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i Test> is simply dummy text of the <i Test> printing and typesetting <i Test> industry. Lorem Ipsum has been the industry's standard dummy text <i Test> ever since the <i Test> 1500s, when <i Test><i Test><i Test><i Test><i Test><i Test><i Test> an unknown printer took a galley of type and scrambled it to make a type specimen book.";
const string strg = "<b>Lorem</b> Ipsum <i Test> is simply dummy text of the <i Test> printing and typesetting <i Test> industry. Lorem Ipsum has been the industry's standard dummy text <i Test> ever since the <i Test> 1500s, when <i Test><i Test><i Test><i Test><i Test><i Test><i Test> an unknown printer took a galley of type and scrambled it to make a type specimen <b></b>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]
Expand Down

0 comments on commit 4c378f7

Please sign in to comment.