Skip to content

Commit 5595e27

Browse files
authored
Update IME ESC key handling
1 parent 5162b2d commit 5595e27

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

src/TSMapEditor/UI/IME/IMEHandler.cs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,6 @@ protected virtual void OnIMETextInput(char character)
7979

8080
LastActionIMEChatInput = true;
8181

82-
// Handle ESC. The IME reports ESC key as a text input.
83-
if (character == 27)
84-
{
85-
LastActionIMEChatInput = false;
86-
if (HandleEscapeKey())
87-
{
88-
// Do not return this ESC key back to the textbox if HandleEscapeKey returns true.
89-
return;
90-
}
91-
else
92-
{
93-
// handleChatInput() method rejects the ESC message. Therefore, we need to manually clear the TextBox here.
94-
if (IMEFocus != null)
95-
{
96-
// TODO: wrap this logic as a new action in RegisterXNATextBox(). This requires an API breaking change on XNAUI, and therefore left as a TODO.
97-
IMEFocus.Text = string.Empty;
98-
}
99-
100-
return;
101-
}
102-
}
103-
10482
if (IMEFocus != null)
10583
{
10684
TextBoxHandleChatInputCallbacks.TryGetValue(IMEFocus, out var handleChatInput);
@@ -228,21 +206,17 @@ bool IIMEHandler.HandleEnterKey(XNATextBox sender)
228206
=> false;
229207

230208
bool IIMEHandler.HandleEscapeKey(XNATextBox sender)
231-
{
232-
return HandleEscapeKey();
233-
}
234-
235-
private bool HandleEscapeKey()
236209
{
237210
//Debug.WriteLine($"IME: HandleEscapeKey: handled: {IMEEventReceived}");
238211

239-
// This method disables the ESC handling of the TextBox as long as the user has used IME.
240-
// This is because IME users often use ESC to cancel composition, and even if currently the composition is empty,
212+
// This method disables the ESC handling of the TextBox as long as the user has ever used IME.
213+
// This is because IME users often use ESC to cancel composition. Even if currently the composition is empty,
241214
// the user still expects ESC to cancel composition rather than deleting the whole sentence.
242215
// For example, the user might mistakenly hit ESC key twice to cancel composition -- deleting the whole sentence is definitely a heavy punishment for such a small mistake.
243216

244-
// Note: "!string.IsNullOrEmpty(Composition) =>IMEEventReceived" should hold, but just in case
245-
return IMEEventReceived || !string.IsNullOrEmpty(Composition);
217+
// Note: "!CompositionEmpty => IMEEventReceived" should hold, but just in case
218+
219+
return IMEEventReceived || !CompositionEmpty;
246220
}
247221

248222
void IIMEHandler.OnTextChanged(XNATextBox sender) { }

0 commit comments

Comments
 (0)