Skip to content

Commit

Permalink
Fix issues with Japanese & Vietnamese IME (microsoft#13678)
Browse files Browse the repository at this point in the history
This commit builds directly on the changes made in microsoft#13677 and fixes:
* TSF resetting to AlphaNumeric ("ASCII") input mode when pressing enter
* Vietnamese IME not composing a new word after pressing whitespace, etc.

Closes microsoft#11479
Closes microsoft#13398

## Validation Steps Performed
* Japanese IME (Full-Width Katakana)
  Typing "saitama" produces "サイタマ" ✅
* Korean IME
  Typing "gksrmf" produces "한글" ✅
* Vietnamese IME
  Typing "xin chaof" produces "xin chào" ✅
* Emoji Picker (Win+.)
  ✅
  • Loading branch information
lhecker authored Aug 11, 2022
1 parent ea04823 commit ed800dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ CFuzz
cgscrn
chafa
changelist
chaof
charinfo
charset
CHARSETINFO
Expand Down Expand Up @@ -2763,6 +2764,9 @@ xes
xff
XFile
XFORM
xin
xinchaof
xinxinchaof
XManifest
XMath
XMFLOAT
Expand Down
4 changes: 1 addition & 3 deletions src/cascadia/TerminalControl/TSFInputControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_inputBuffer.clear();
_selection = {};
_activeTextStart = 0;
_editContext.NotifyFocusLeave();
_editContext.NotifyTextChanged({ 0, INT32_MAX }, 0, _selection);
_editContext.NotifyFocusEnter();
TextBlock().Text({});
}
}
Expand Down Expand Up @@ -375,7 +373,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
incomingText);
_selection = args.NewSelection();
// GH#5054: Pressing backspace might move the caret before the _activeTextStart.
_activeTextStart = ::base::ClampMin(_activeTextStart, ::base::ClampedNumeric<size_t>(range.StartCaretPosition));
_activeTextStart = std::min(_activeTextStart, _inputBuffer.size());

// Emojis/Kaomojis/Symbols chosen through the IME without starting composition
// will be sent straight through to the terminal.
Expand Down
19 changes: 13 additions & 6 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return;
}

// GH#11479: TSF wants to be notified of any character input via ICoreTextEditContext::NotifyTextChanged().
// TSF is built and tested around the idea that you inform it of any text changes that happen
// when it doesn't currently compose characters. For instance writing "xin chaof" with the
// Vietnamese IME should produce "xin chào". After writing "xin" it'll emit a composition
// completion event and we'll write "xin" to the shell. It now has no input focus and won't know
// about the whitespace. If you then write "chaof", it'll emit another composition completion
// event for "xinchaof" and the resulting output in the shell will finally read "xinxinchaof".
// A composition completion event technically doesn't mean that the completed text is now
// immutable after all. We could (and probably should) inform TSF of any input changes,
// but we technically aren't a text input field. The immediate solution was
// to simply force TSF to clear its text whenever we have input focus.
TSFInputControl().ClearBuffer();

_HidePointerCursorHandlers(*this, nullptr);

const auto ch = e.Character();
Expand Down Expand Up @@ -1193,12 +1206,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
const auto window = CoreWindow::GetForCurrentThread();

if (vkey == VK_ESCAPE ||
vkey == VK_RETURN)
{
TSFInputControl().ClearBuffer();
}

// If the terminal translated the key, mark the event as handled.
// This will prevent the system from trying to get the character out
// of it and sending us a CharacterReceived event.
Expand Down

0 comments on commit ed800dc

Please sign in to comment.