diff --git a/MLEM/Formatting/FormattingCodeCollection.cs b/MLEM/Formatting/FormattingCodeCollection.cs index f3ee385..af3380b 100644 --- a/MLEM/Formatting/FormattingCodeCollection.cs +++ b/MLEM/Formatting/FormattingCodeCollection.cs @@ -1,7 +1,22 @@ using System.Collections.Generic; +using System.Text.RegularExpressions; namespace MLEM.Formatting { - public class FormattingCodeCollection : Dictionary> { + public class FormattingCodeCollection : Dictionary> { + + } + + public class FormattingCodeData { + + public readonly FormattingCode Code; + public readonly Match Match; + public readonly int UnformattedIndex; + + public FormattingCodeData(FormattingCode code, Match match, int unformattedIndex) { + this.Code = code; + this.Match = match; + this.UnformattedIndex = unformattedIndex; + } } } \ No newline at end of file diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index 49b7e85..6947741 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -70,10 +70,11 @@ namespace MLEM.Formatting { if (code == null) continue; var index = match.Index - codeLengths; + var data = new FormattingCodeData(code, match, index); if (codes.TryGetValue(index, out var curr)) { - curr.Add(code); + curr.Add(data); } else { - codes.Add(index, new List {code}); + codes.Add(index, new List {data}); } codeLengths += match.Length - code.GetReplacementString(font).Length; } @@ -93,7 +94,8 @@ namespace MLEM.Formatting { foreach (var c in unformattedText) { // check if the current character's index has a formatting code if (formatting.TryGetValue(formatIndex, out var codes)) { - foreach (var code in codes) { + foreach (var data in codes) { + var code = data.Code; // if so, apply it switch (code.CodeType) { case FormattingCode.Type.Color: