Repository: microsoft/terminal (language: cpp)

Issue:
Feature request: Set IME input mode to English when a Windows Terminal window is opened
# Description of the new feature/enhancement

I'm using the Microsoft Chinese IMEs, and when I open a Windows Terminal window, the input mode will be set to Chinese.

I know that's because the IME's "default mode" is set to Chinese (which is also the system default setting). If I change its "default mode" to English then the input mode will be English when I open Windows Terminal.

But I also noticed that even with the "default mode" set to Chinese, if you open Command Prompt (or other programs hosted by conhost.exe), the IME mode will still be switched to English, because users are more likely to input English texts.

So setting the input mode to English when Windows Terminal is launched would be helpful, as most command line texts are in English.

For Sougou Pinyin IME users: seems that Sougou Pinyin does not respect the "default input mode" set by those programs, because opening a Command Prompt window won't change its input mode to English.

I actually found a similar issue #1304 that further requested to restore input mode to English each time users hit Enter or Esc. That may be even better, although changing input mode so often might confuse some users. Personally I just want Windows Terminal to have English input mode on startup like what conhost does, so I can type in commands immediately.


Discussion / hints:
If this is something that conhost already does, then this should be fairly trivial to implement for the Terminal, and it'd be all the precedent needed to do it. I'm worried that this is something that the IME does on behalf of conhost - detecting that conhost is the foreground window and then switching automatically. 

If that's the case, this might be quite a bit harder to fix, requiring a fix in the OS itself.
I didn't go deep, but have done a little testing to try and solve the same problem.

In terms of test results, there should be at least ~~two~~_(edited: maybe only one)_ factors affecting the default input mode for window programs:

- ~~When the window class is ConsoleWindowClass, the input mode will be set to english regardless of the default value.~~_(edited: There was an error in the previous test, because specifying WindowClass alone was far from enough to create an interactive console window, therefore, the above conclusions are only inferences based on limited indirect tests, which are in fact wrong. Finally, it was found that the real impact was the process name of conhost.exe, If it was renamed, any shells hosted on it will no longer automatically switch to the English input mode.)_

- When the process name is cmd.exe, powershell.exe, bash.exe or conhost.exe, the input mode will be set to english regardless of the default value. _(edited: supplement known process name)_

Looks more like it's determined by the Microsoft Pinyin itself, especially the second. When I rename other programs like notepad.exe to cmd.exe, it will accept English input by default. 

~~For the first item, because there is no language related field in WNDCLASS or WNDCLASSEX structure, so I can only think that this ConsoleWindowClass has an extra contract with the system or Microsoft Pinyin.~~ _(edited: It doesn't matter because the first item above does not actually affect.)_

The input area window class of windows terminal is Windows.UI.Input.InputSite.WindowClass, 
I also didn't find the relevant settings, so I gave up.

_The example in this [link](https://docs.microsoft.com/en-us/windows/apps/design/globalizing/manage-language-and-region#app-manifest-language-list) might be useful, but I didn't test it._
Well, that's certainly great research! It's maybe a little troubling that this is something that seems to be outside our codebase. If this is something that's truly just a heuristic by Microsoft Pinyin, that just means it's gonna be less likely we can just patch that on our side. 
> Well, that's certainly great research! It's maybe a little troubling that this is something that seems to be outside our codebase. If this is something that's truly just a heuristic by Microsoft Pinyin, that just means it's gonna be less likely we can just patch that on our side.

I think I found a way:

[in src\cascadia\TerminalControl\TSFInputControl.cpp:41:](https://github.com/microsoft/terminal/blob/87f5034db1eb0102358d05eeff82ebcc8032c9be/src/cascadia/TerminalControl/TSFInputControl.cpp#L41)
``` cpp
        _editContext.InputScope(CoreTextInputScope::Text);
```

Just simply change the `CoreTextInputScope::Text` to `CoreTextInputScope::AlphanumericHalfWidth` should work.

- `CoreTextInputScope::AlphanumericHalfWidth` makes the input box accept English by default, and can be manually changed to Chinese Pinyin with the shift key, which is exactly the effect we want. 
Although its name limits the characters to half-width, the input method can still enter full-width characters. 
- `CoreTextInputScope::Password` can also make the input box accept English input by default, but it will prevent the input method from being manually switched to Chinese Pinyin.

**NOTICE:**  I have not actually tested the above code in this project, but completed the feasibility verification in another simple project which is just for testing, then I searched the entire [microsoft/terminal](https://github.com/microsoft/terminal) project and found the only place InputScope appears and wrote this comment.
I have actually verified in this project that `_editContext.InputScope(CoreTextInputScope::AlphanumericHalfWidth)` works as expected, the remaining question is whether this change will cause dissatisfaction among some other users?

Or to be on the safe side, make the inputScope customizable through the configuration file maybe a better choice, I can handle it if necessary.

Fix patch:
diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp
index efac84e2917..6f4abc6371b 100644
--- a/src/cascadia/TerminalControl/TSFInputControl.cpp
+++ b/src/cascadia/TerminalControl/TSFInputControl.cpp
@@ -37,8 +37,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
         // InputPane is manually shown inside of TermControl.
         _editContext.InputPaneDisplayPolicy(CoreTextInputPaneDisplayPolicy::Manual);
 
-        // set the input scope to Text because this control is for any text.
-        _editContext.InputScope(CoreTextInputScope::Text);
+        // Set the input scope to AlphanumericHalfWidth in order to facilitate those CJK input methods to open in English mode by default.
+        // AlphanumericHalfWidth scope doesn't prevent input method from switching to composition mode, it accepts any character too.
+        // Besides, Text scope turns on typing intelligence, but that doesn't work in this project.
+        _editContext.InputScope(CoreTextInputScope::AlphanumericHalfWidth);
 
         _textRequestedRevoker = _editContext.TextRequested(winrt::auto_revoke, { this, &TSFInputControl::_textRequestedHandler });
 


Test patch: