Skip to content

Commit f2534a9

Browse files
committed
Fix issues with Japanese & Vietnamese IME
1 parent 2c922e1 commit f2534a9

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

.github/actions/spelling/expect/expect.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ antialias
4242
antialiasing
4343
ANull
4444
anycpu
45-
AOn
4645
APARTMENTTHREADED
4746
APCs
4847
api
@@ -80,7 +79,6 @@ ASingle
8079
asm
8180
asmv
8281
asmx
83-
AStomps
8482
ASYNCWINDOWPOS
8583
atch
8684
ATest
@@ -225,14 +223,14 @@ CFuzz
225223
cgscrn
226224
chafa
227225
changelist
226+
chaof
228227
charinfo
229228
charset
230229
CHARSETINFO
231230
chcp
232231
checkbox
233232
checkboxes
234233
chh
235-
Childitem
236234
chk
237235
chrono
238236
CHT
@@ -2756,6 +2754,9 @@ xes
27562754
xff
27572755
XFile
27582756
XFORM
2757+
xin
2758+
xinchaof
2759+
xinxinchaof
27592760
XManifest
27602761
XMath
27612762
XMFLOAT

src/cascadia/TerminalControl/TSFInputControl.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
102102
_inputBuffer.clear();
103103
_selection = {};
104104
_activeTextStart = 0;
105-
_editContext.NotifyFocusLeave();
106105
_editContext.NotifyTextChanged({ 0, INT32_MAX }, 0, _selection);
107-
_editContext.NotifyFocusEnter();
108106
TextBlock().Text({});
109107
}
110108
}
@@ -375,7 +373,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
375373
incomingText);
376374
_selection = args.NewSelection();
377375
// GH#5054: Pressing backspace might move the caret before the _activeTextStart.
378-
_activeTextStart = ::base::ClampMin(_activeTextStart, ::base::ClampedNumeric<size_t>(range.StartCaretPosition));
376+
_activeTextStart = std::min(_activeTextStart, _inputBuffer.size());
379377

380378
// Emojis/Kaomojis/Symbols chosen through the IME without starting composition
381379
// will be sent straight through to the terminal.

src/cascadia/TerminalControl/TermControl.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
921921
return;
922922
}
923923

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

926939
const auto ch = e.Character();
@@ -1182,12 +1195,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
11821195
{
11831196
const auto window = CoreWindow::GetForCurrentThread();
11841197

1185-
if (vkey == VK_ESCAPE ||
1186-
vkey == VK_RETURN)
1187-
{
1188-
TSFInputControl().ClearBuffer();
1189-
}
1190-
11911198
// If the terminal translated the key, mark the event as handled.
11921199
// This will prevent the system from trying to get the character out
11931200
// of it and sending us a CharacterReceived event.

0 commit comments

Comments
 (0)