Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions src/TSMapEditor/UI/IME/IMEHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,6 @@ protected virtual void OnIMETextInput(char character)

LastActionIMEChatInput = true;

// Handle ESC. The IME reports ESC key as a text input.
if (character == 27)
{
LastActionIMEChatInput = false;
if (HandleEscapeKey())
{
// Do not return this ESC key back to the textbox if HandleEscapeKey returns true.
return;
}
else
{
// handleChatInput() method rejects the ESC message. Therefore, we need to manually clear the TextBox here.
if (IMEFocus != null)
{
// TODO: wrap this logic as a new action in RegisterXNATextBox(). This requires an API breaking change on XNAUI, and therefore left as a TODO.
IMEFocus.Text = string.Empty;
}

return;
}
}

if (IMEFocus != null)
{
TextBoxHandleChatInputCallbacks.TryGetValue(IMEFocus, out var handleChatInput);
Expand Down Expand Up @@ -228,21 +206,17 @@ bool IIMEHandler.HandleEnterKey(XNATextBox sender)
=> false;

bool IIMEHandler.HandleEscapeKey(XNATextBox sender)
{
return HandleEscapeKey();
}

private bool HandleEscapeKey()
{
//Debug.WriteLine($"IME: HandleEscapeKey: handled: {IMEEventReceived}");

// This method disables the ESC handling of the TextBox as long as the user has used IME.
// This is because IME users often use ESC to cancel composition, and even if currently the composition is empty,
// This method disables the ESC handling of the TextBox as long as the user has ever used IME.
// This is because IME users often use ESC to cancel composition. Even if currently the composition is empty,
// the user still expects ESC to cancel composition rather than deleting the whole sentence.
// 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.

// Note: "!string.IsNullOrEmpty(Composition) =>IMEEventReceived" should hold, but just in case
return IMEEventReceived || !string.IsNullOrEmpty(Composition);
// Note: "!CompositionEmpty => IMEEventReceived" should hold, but just in case

return IMEEventReceived || !CompositionEmpty;
}

void IIMEHandler.OnTextChanged(XNATextBox sender) { }
Expand Down
Loading