diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index d3b649d..59f8aa5 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -536,54 +536,24 @@ internal sealed class ChatLog : IUiComponent { ImGui.PushStyleColor(ImGuiCol.Text, ColourUtil.RgbaToAbgr(inputColour.Value)); } + var chatCopy = this.Chat; ImGui.SetNextItemWidth(inputWidth); - const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.EnterReturnsTrue - | ImGuiInputTextFlags.CallbackAlways + const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.CallbackAlways | ImGuiInputTextFlags.CallbackCharFilter | ImGuiInputTextFlags.CallbackCompletion | ImGuiInputTextFlags.CallbackHistory; - if (ImGui.InputText("##chat2-input", ref this.Chat, 500, inputFlags, this.Callback)) { - if (!string.IsNullOrWhiteSpace(this.Chat)) { - var trimmed = this.Chat.Trim(); - this.AddBacklog(trimmed); - this._inputBacklogIdx = -1; + ImGui.InputText("##chat2-input", ref this.Chat, 500, inputFlags, this.Callback); - if (!trimmed.StartsWith('/')) { - if (this._tellTarget != null) { - var target = this._tellTarget; - var reason = target.Reason; - var world = this.Ui.Plugin.DataManager.GetExcelSheet()?.GetRow(target.World); - if (world is { IsPublic: true }) { - if (reason == TellReason.Reply && this.Ui.Plugin.Common.Functions.FriendList.List.Any(friend => friend.ContentId == target.ContentId)) { - reason = TellReason.Friend; - } - - this.Ui.Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, trimmed); - } - - if (this._tempChannel is InputChannel.Tell) { - this._tellTarget = null; - } - - goto Skip; - } - - - if (this._tempChannel != null) { - trimmed = $"{this._tempChannel.Value.Prefix()} {trimmed}"; - } else if (activeTab is { Channel: { } channel }) { - trimmed = $"{channel.Prefix()} {trimmed}"; - } - } - - var bytes = Encoding.UTF8.GetBytes(trimmed); - AutoTranslate.ReplaceWithPayload(this.Ui.Plugin.DataManager, ref bytes); - - this.Ui.Plugin.Common.Functions.Chat.SendMessageUnsafe(bytes); + if (ImGui.IsItemDeactivated()) { + if (ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Escape))) { + this.Chat = chatCopy; + } + + var enter = ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Enter)) + || ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.KeyPadEnter)); + if (enter) { + this.SendChatBox(activeTab); } - - Skip: - this.Chat = string.Empty; } if (ImGui.IsItemActive()) { @@ -635,6 +605,50 @@ internal sealed class ChatLog : IUiComponent { return true; } + private void SendChatBox(Tab? activeTab) { + if (!string.IsNullOrWhiteSpace(this.Chat)) { + var trimmed = this.Chat.Trim(); + this.AddBacklog(trimmed); + this._inputBacklogIdx = -1; + + if (!trimmed.StartsWith('/')) { + if (this._tellTarget != null) { + var target = this._tellTarget; + var reason = target.Reason; + var world = this.Ui.Plugin.DataManager.GetExcelSheet()?.GetRow(target.World); + if (world is { IsPublic: true }) { + if (reason == TellReason.Reply && this.Ui.Plugin.Common.Functions.FriendList.List.Any(friend => friend.ContentId == target.ContentId)) { + reason = TellReason.Friend; + } + + this.Ui.Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, trimmed); + } + + if (this._tempChannel is InputChannel.Tell) { + this._tellTarget = null; + } + + goto Skip; + } + + + if (this._tempChannel != null) { + trimmed = $"{this._tempChannel.Value.Prefix()} {trimmed}"; + } else if (activeTab is { Channel: { } channel }) { + trimmed = $"{channel.Prefix()} {trimmed}"; + } + } + + var bytes = Encoding.UTF8.GetBytes(trimmed); + AutoTranslate.ReplaceWithPayload(this.Ui.Plugin.DataManager, ref bytes); + + this.Ui.Plugin.Common.Functions.Chat.SendMessageUnsafe(bytes); + } + + Skip: + this.Chat = string.Empty; + } + internal void UserHide() { this._hideState = HideState.User; }