diff --git a/Content.Client/UserInterface/Systems/Chat/ChatUIController.Highlighting.cs b/Content.Client/UserInterface/Systems/Chat/ChatUIController.Highlighting.cs index e413999b2c..1670823aab 100644 --- a/Content.Client/UserInterface/Systems/Chat/ChatUIController.Highlighting.cs +++ b/Content.Client/UserInterface/Systems/Chat/ChatUIController.Highlighting.cs @@ -14,12 +14,17 @@ namespace Content.Client.UserInterface.Systems.Chat; /// public sealed partial class ChatUIController : IOnSystemChanged { + [Dependency] private readonly ILocalizationManager _loc = default!; [UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!; + private static readonly Regex StartDoubleQuote = new("\"$"); + private static readonly Regex EndDoubleQuote = new("^\"|(?<=^@)\""); + private static readonly Regex StartAtSign = new("^@"); + /// /// The list of words to be highlighted in the chatbox. /// - private List _highlights = new(); + private readonly List _highlights = new(); /// /// The string holding the hex color used to highlight words. @@ -42,7 +47,7 @@ public sealed partial class ChatUIController : IOnSystemChanged { _highlightsColor = value; }, true); // Load highlights if any were saved. - string highlights = _config.GetCVar(CCVars.ChatHighlights); + var highlights = _config.GetCVar(CCVars.ChatHighlights); if (!string.IsNullOrEmpty(highlights)) { @@ -84,12 +89,12 @@ public sealed partial class ChatUIController : IOnSystemChanged (c == '"')) > 0) + if (keyword.Any(c => c == '"')) { // Matches the last double quote character. - keyword = Regex.Replace(keyword, "\"$", "(?!\\w)"); + keyword = StartDoubleQuote.Replace(keyword, "(?!\\w)"); // When matching for the first double quote character we also consider the possibility // of the double quote being preceded by a @ character. - keyword = Regex.Replace(keyword, "^\"|(?<=^@)\"", "(? (c == ' ' || c == '-')) == 1) @@ -144,9 +149,9 @@ public sealed partial class ChatUIController : IOnSystemChanged