Skip to content

Commit 852d474

Browse files
committed
Update IMEHandler.cs
1 parent 3edd6e9 commit 852d474

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

ClientGUI/IME/IMEHandler.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#nullable enable
22
using System;
3+
using System.Collections.Concurrent;
34
using System.Collections.Generic;
45
using System.Diagnostics;
56

67
using Microsoft.Xna.Framework;
78

9+
using Rampastring.XNAUI;
810
using Rampastring.XNAUI.Input;
911
using Rampastring.XNAUI.XNAControls;
1012

@@ -52,7 +54,7 @@ private void OnCompositionChanged(string oldValue, string newValue)
5254
LastActionIMEChatInput = false;
5355
}
5456

55-
protected Dictionary<XNATextBox, Action<char>?> TextBoxHandleChatInputCallbacks = [];
57+
protected ConcurrentDictionary<XNATextBox, Action<char>?> TextBoxHandleChatInputCallbacks = [];
5658

5759
public virtual int CompositionCursorPosition { get; set; }
5860

@@ -92,6 +94,15 @@ private void SetIMETextInputRectangle(XNATextBox sender)
9294
var rect = sender.RenderRectangle();
9395
rect.X += sender.WindowManager.SceneXPosition;
9496
rect.Y += sender.WindowManager.SceneYPosition;
97+
98+
// Following the input cursor
99+
// This requires SetIMETextInputRectangle() be called whenever InputPosition is changed.
100+
101+
//var vec = Renderer.GetTextDimensions(
102+
// sender.Text.Substring(sender.TextStartPosition, sender.TextEndPosition - sender.InputPosition),
103+
// sender.FontIndex);
104+
//rect.X += (int)vec.X;
105+
95106
SetTextInputRectangle(rect);
96107
}
97108

@@ -128,10 +139,10 @@ void IIMEHandler.OnSelectedChanged(XNATextBox sender)
128139
}
129140

130141
void IIMEHandler.RegisterXNATextBox(XNATextBox sender, Action<char>? handleCharInput) =>
131-
TextBoxHandleChatInputCallbacks.Add(sender, handleCharInput);
142+
TextBoxHandleChatInputCallbacks[sender] = handleCharInput;
132143

133144
void IIMEHandler.KillXNATextBox(XNATextBox sender) =>
134-
TextBoxHandleChatInputCallbacks.Remove(sender);
145+
TextBoxHandleChatInputCallbacks.TryRemove(sender, out _);
135146

136147
bool IIMEHandler.HandleScrollLeftKey(XNATextBox sender) => !CompositionEmpty;
137148

0 commit comments

Comments
 (0)