From dba01de388655754806f8a6c24bba19509adb198 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Sun, 12 May 2024 17:56:53 -0700 Subject: [PATCH] Merge pull request #44 * fix: various bug fixes --- ChatTwo/Chunk.cs | 8 ++++++-- ChatTwo/Ui/ChatLogWindow.cs | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChatTwo/Chunk.cs b/ChatTwo/Chunk.cs index f7a096e..f30b248 100755 --- a/ChatTwo/Chunk.cs +++ b/ChatTwo/Chunk.cs @@ -72,7 +72,9 @@ public class TextChunk : Chunk internal TextChunk(ChunkSource source, Payload? link, string content) : base(source, link) { - Content = content; + // This has been null in the past, and it broke rendering code. + // ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract + Content = content ?? ""; } // ReSharper disable once UnusedMember.Global // Used by MessagePack @@ -82,7 +84,9 @@ public class TextChunk : Chunk Foreground = foreground; Glow = glow; Italic = italic; - Content = content; + // See above. + // ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract + Content = content ?? ""; } /// diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index 63fceea..dba351b 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -1012,6 +1012,10 @@ public sealed class ChatLogWindow : Window ImGui.TextUnformatted(timestamp); lastTimestamp = timestamp; } + else + // Avoids rendering issues caused by emojis in + // message content. + ImGui.TextUnformatted(""); } else { @@ -1480,8 +1484,12 @@ public sealed class ChatLogWindow : Window internal void DrawChunks(IReadOnlyList chunks, bool wrap = true, PayloadHandler? handler = null, float lineWidth = 0f) { using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero); + for (var i = 0; i < chunks.Count; i++) { + if (chunks[i] is TextChunk text && string.IsNullOrEmpty(text.Content)) + continue; + DrawChunk(chunks[i], wrap, handler, lineWidth); if (i < chunks.Count - 1) @@ -1556,7 +1564,12 @@ public sealed class ChatLogWindow : Window // Check for contains here as sometimes there are multiple // TextChunks with the same PlayerPayload but only one has the name. // E.g. party chat with cross world players adds extra chunks. - var content = text.Content; + // + // Note: This has been null before, I'm guessing due to some issues with + // other plugins. New TextChunks will now enforce empty string in ctor, + // but old ones may still be null. + // ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract + var content = text.Content ?? ""; if (ScreenshotMode) { if (chunk.Link is PlayerPayload playerPayload && content.Contains(playerPayload.PlayerName))