From 852d474c6562e250936a4da3565570e931469145 Mon Sep 17 00:00:00 2001 From: SadPencil Date: Fri, 24 Jan 2025 17:59:45 +0800 Subject: [PATCH] Update IMEHandler.cs --- ClientGUI/IME/IMEHandler.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ClientGUI/IME/IMEHandler.cs b/ClientGUI/IME/IMEHandler.cs index 67b35a4e3..68fd5b4ee 100644 --- a/ClientGUI/IME/IMEHandler.cs +++ b/ClientGUI/IME/IMEHandler.cs @@ -1,10 +1,12 @@ #nullable enable using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using Microsoft.Xna.Framework; +using Rampastring.XNAUI; using Rampastring.XNAUI.Input; using Rampastring.XNAUI.XNAControls; @@ -52,7 +54,7 @@ private void OnCompositionChanged(string oldValue, string newValue) LastActionIMEChatInput = false; } - protected Dictionary?> TextBoxHandleChatInputCallbacks = []; + protected ConcurrentDictionary?> TextBoxHandleChatInputCallbacks = []; public virtual int CompositionCursorPosition { get; set; } @@ -92,6 +94,15 @@ private void SetIMETextInputRectangle(XNATextBox sender) var rect = sender.RenderRectangle(); rect.X += sender.WindowManager.SceneXPosition; rect.Y += sender.WindowManager.SceneYPosition; + + // Following the input cursor + // This requires SetIMETextInputRectangle() be called whenever InputPosition is changed. + + //var vec = Renderer.GetTextDimensions( + // sender.Text.Substring(sender.TextStartPosition, sender.TextEndPosition - sender.InputPosition), + // sender.FontIndex); + //rect.X += (int)vec.X; + SetTextInputRectangle(rect); } @@ -128,10 +139,10 @@ void IIMEHandler.OnSelectedChanged(XNATextBox sender) } void IIMEHandler.RegisterXNATextBox(XNATextBox sender, Action? handleCharInput) => - TextBoxHandleChatInputCallbacks.Add(sender, handleCharInput); + TextBoxHandleChatInputCallbacks[sender] = handleCharInput; void IIMEHandler.KillXNATextBox(XNATextBox sender) => - TextBoxHandleChatInputCallbacks.Remove(sender); + TextBoxHandleChatInputCallbacks.TryRemove(sender, out _); bool IIMEHandler.HandleScrollLeftKey(XNATextBox sender) => !CompositionEmpty;