diff --git a/CHANGELOG.md b/CHANGELOG.md index a78190d..76ea7ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Improvements Fixes - Fixed TokenizedString handling trailing spaces incorrectly in the last line of non-left aligned text +- Fixed some TokenizedString tokens starting with a line break not being split correctly ### MLEM.Ui Additions diff --git a/MLEM/Formatting/TokenizedString.cs b/MLEM/Formatting/TokenizedString.cs index 22c747d..fb70db9 100644 --- a/MLEM/Formatting/TokenizedString.cs +++ b/MLEM/Formatting/TokenizedString.cs @@ -229,16 +229,10 @@ namespace MLEM.Formatting { if (endsLater) { for (var i = tokenIndex + 1; i < this.Tokens.Length; i++) { var other = this.Tokens[i]; - var otherFont = other.GetFont(defaultFont); - if (other.SplitDisplayString.Length > 1) { - // the line ends in this token (so we also ignore trailing whitespaces) - restOfLine += otherFont.MeasureString(other.SplitDisplayString[0], true).X; + restOfLine += other.GetFont(defaultFont).MeasureString(other.SplitDisplayString[0], true).X; + // if the token's split display string has multiple lines, then the line ends in it, which means we can stop + if (other.SplitDisplayString.Length > 1) break; - } else { - // the line doesn't end in this token (or it's the last token), so add it fully - var lastToken = i >= this.Tokens.Length - 1; - restOfLine += otherFont.MeasureString(other.DisplayString, lastToken).X; - } } } if (alignment == TextAlignment.Center)