Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Japanese IME input mode switched back to Direct Input after pressing Enter key #13398

Closed
rabianr opened this issue Jun 29, 2022 · 22 comments · Fixed by #13678
Closed

Japanese IME input mode switched back to Direct Input after pressing Enter key #13398

rabianr opened this issue Jun 29, 2022 · 22 comments · Fixed by #13678
Assignees
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.

Comments

@rabianr
Copy link

rabianr commented Jun 29, 2022

Windows Terminal version

1.14.1451.0

Windows build number

10.0.19044.1766

Other Software

No response

Steps to reproduce

  • Turn on Hiragana input mode
  • Type something then press Enter to convert to japanese

Expected Behavior

The input mode should not switch back to Direct Input

Actual Behavior

The input mode switched to Direct Input automatically after conversion

terminal

@rabianr rabianr added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Jun 29, 2022
@ghost ghost added Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jun 29, 2022
@driver1998
Copy link

Might be related: #12731

@driver1998
Copy link

If we can't have a smarter way to detect when should we use compose mode and when should we use direct input, I would like to have an option to disable this behavior. Since I already installed a separate English (US) language along side Chinese (Simplified, MS Pinyin) so that I can turn off IME for good if I don't need it.

@driver1998
Copy link

driver1998 commented Jul 6, 2022

At least MS Pinyin handles it this way with conhost:

On first start of conhost, uses direct input by default.
If user enables compose mode with Shift, do not automatically switch back to direct mode.

@tadashi-aikawa
Copy link

I have encountered this issue, and it never occurred in previous versions.

When I write a git commit message mixed in English(alphabet) and Japanese, I often commit unintentional messages. (and have to amend commit again...)

Best regards.

@rabianr
Copy link
Author

rabianr commented Jul 22, 2022

Might be related: #12731

It's indeed related as the problem occurred after upgrading to v1.14.1432.

Hope that there is a way to disable this behavior, because I tend to press enter key to end IME composition.
Automatically switch back to direct mode each time make it hard to input Japanese text in the terminal.

@BingFengHung
Copy link

I also have the same problem.

When I type Chinese, then I press enter it jumps to English IME.
But I am not done with my Chinese typing.

@yuru7
Copy link

yuru7 commented Jul 24, 2022

This problem does not occur with Google Japanese Input.
However, there is a bug that it automatically switches to "HankakuEisu" mode when starting Windows Terminal.

20220724_121850

@shinsaka
Copy link

I'm having the same problem with MS-IME on Windows Terminal version 1.14.1963.0.
I hope it fixes. 🙏

@YossyHal
Copy link

When the Microsoft IME version was lowered, this event no longer occurred.
image

@ironsand
Copy link

ironsand commented Jul 29, 2022

When the Microsoft IME version was lowered, this event no longer occurred.

It didn't work for me. Does someone know other work-arounds?

@yuru7
Copy link

yuru7 commented Jul 29, 2022

If finalize with Ctrl-m instead of Enter, the IME will not turn off. But it is incredibly annoying method 😅

You could write following AutoHotKey script based on the hack.

#IfWinActive, ahk_exe WindowsTerminal.exe
  Enter::Send, ^{m}
#If

@megane42
Copy link

I'm running into the same issue.

In my environment, I can avoid the issue by waiting 0.5 - 1.0 seconds before pushing enter. Hope this helps some debugging.

@hqf00342
Copy link

hqf00342 commented Jul 31, 2022

I also have the same problem.
In my case, the workaround mentioned by @YossyHal works fine. (ver1.14.1963.0, on Windows11 22000.795)

When the Microsoft IME version was lowered, this event no longer occurred.

ty.

@zadjii-msft
Copy link
Member

zadjii-msft commented Aug 1, 2022

I wonder if there's a way to only request AlphanumericHalfWidth the very first time the IME opens for a pane, and then just continue using the previously used mode for subsequent invocations.

@YanceyChiew as an FYI. I'm not as familiar with the intricacies of the IME APIs, so you might have some better ideas here.

Link for future me: #13028

@zadjii-msft zadjii-msft added Area-Input Related to input processing (key presses, mouse, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Product-Terminal The new Windows Terminal. Priority-1 A description (P1) labels Aug 1, 2022
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Aug 1, 2022
@zadjii-msft zadjii-msft added this to the Terminal v1.16 milestone Aug 1, 2022
@zadjii-msft zadjii-msft added Needs-Discussion Something that requires a team discussion before we can proceed and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Aug 1, 2022
@zadjii-msft zadjii-msft removed the Needs-Discussion Something that requires a team discussion before we can proceed label Aug 1, 2022
@YanceyChiew
Copy link
Contributor

YanceyChiew commented Aug 2, 2022

I wonder if there's a way to only request AlphanumericHalfWidth the very first time the IME opens for a pane, and then just continue using the previously used mode for subsequent invocations.

In short, yes, there is.

This is the default behavior for Chinese input, so I thought there was no need for additional processing, but I didn't expect it to cause trouble for Japanese input method users.


The root of the problem lies in these few lines of code:

    void TSFInputControl::ClearBuffer()
    {
        if (!_inputBuffer.empty())
        {
            TextBlock().Text(L"");
            const auto bufLen = ::base::ClampedNumeric<int32_t>(_inputBuffer.length());
            _inputBuffer.clear();
            _editContext.NotifyFocusLeave();
            _editContext.NotifyTextChanged({ 0, bufLen }, 0, { 0, 0 });
            _editContext.NotifyFocusEnter();
            _activeTextStart = 0;
            _inComposition = false;
        }
    }

It can be seen that this code will not perform any effective operation when _inputBuffer.empty(), which is consistent with the performance of the Japanese input method that does not exit composition mode when press Enter directly with empty command line.

Maybe it is because the Microsoft Japanese input method is in the English (direct) input mode by default, and it's handling of lost input focus is also different from the Chinese input method, after each call to _editContext.NotifyFocusLeave(), it will exit from the composition input mode to the direct input mode.

Incidentally, in another issue(#1304), someone wanted such a feature, but I found it difficult to implement cleanly.

(ps. When using the old Japanese input method, it will exit to direct input mode when pressing enter only when there are no characters in the input buffer of composition mode, so only newlines will cause composition mode to exit uncontrollably.)


The easiest solution I can think of is to modify the _editContext.InputScope back to CoreTextInputScope::Text as soon as the input method gets focus for the first time. By testing in another example project, I found that it works fine with both Chinese and Japanese input methods.
The key is that the timing of modification should be between the first and second calls to _editContext.NotifyFocusEnter().

But in this project, I haven't found a suitable place to insert that line of code yet. It can also be inserted in the code block quoted above, TermControl will call it when Esc or Enter is pressed, inserting code anywhere before _editContext.NotifyFocusLeave() will take effect in time, but that looks a bit dirty doing pointless operations multiple times.

@hqf00342
Copy link

hqf00342 commented Aug 2, 2022

It seems you are right.
I removed the changes in PR #13028 from the current HEAD(7976e48) source, compiled it, and confirmed that it works fine with the current version of Japanese MS-IME.

I changed the line at at src/cascadia/TerminalControl/TSFInputControl.cpp:43

     _editContext.InputScope(CoreTextInputScope::AlphanumericHalfWidth);

to

     _editContext.InputScope(CoreTextInputScope::Text);

I agree with what you tried to do with your PR #13028,
we would like to find a good way to make both Japanese and Chinese users happy.

P.S.
However, there may be other causes as well.
It seems that this issue only occurs with the current version of Japanese MS-IME, not with Google-Input or MS-IME(previous ver). I also tried ATOK2022, a typical Japanese IME, but it didn't occur this issue.

@YanceyChiew
Copy link
Contributor

However, there may be other causes as well.
It seems that this issue only occurs with the current version of Japanese MS-IME, not with Google-Input or MS-IME(previous ver). I also tried ATOK2022, a typical Japanese IME, but it didn't occur this issue.

This may be because InputScope is not implemented by the two non-Microsoft input methods mentioned above, its enum values ​​are simply ignored. And in my test, the old version of Microsoft Japanese input method will also be affected when wrapping.

@YanceyChiew
Copy link
Contributor

YanceyChiew commented Aug 3, 2022

So, the question now is, use the simple solution to change the _editContext.InputScope back to CoreTextInputScope::Text as soon as the TSFInputControl is connected to the input method for the first time, or add a setting to the _editContext.InputScope as originally envisaged if it doesn't satisfy all users?

Both methods can solve the current problem, If we choose the former, since it cannot be assumed that the window is initialized with input focus, the code may have to be inserted before _editContext.NotifyFocusLeave(), making it itself or the code that determines whether it needs to be executed repeatedly.

Insert code here and it will be repeated every time the window regains focus, not every time enter is pressed.

    void TSFInputControl::NotifyFocusEnter()
    {
        if (_editContext != nullptr)
        {
            _editContext.NotifyFocusEnter();
            _focused = true;
           // CODE INSERT HERE
           // _editContext.InputScope(CoreTextInputScope::Text);
        }
    }

If we choose the latter, do we need to expose the option to the settings page in the gui, and have the default value determined by the user's system locale?

@hqf00342
Copy link

hqf00342 commented Aug 3, 2022

I think we should wait a while for other reports.
cf. @ironsand says that even using an older version of the IME did not work around this issue.

I'd like to vote for "add a setting". And "Set default values determined by the user's system locale" is a good idea. With this, most people will not need to change this setting, so it seems to me that there is no problem even if editing the json is the only way to change this setting. (of course, it would be nice to have a gui)

@zadjii-msft zadjii-msft added the Needs-Discussion Something that requires a team discussion before we can proceed label Aug 3, 2022
@lhecker
Copy link
Member

lhecker commented Aug 4, 2022

I believe the easiest fix is to remove the calls to NotifyFocusLeave() and NotifyFocusEnter() inside TSFInputControl::ClearBuffer(). But I'm currently waiting to see whether I can fix the general behavior of the input first (#11479).

@ghost ghost added the In-PR This issue has a related PR label Aug 4, 2022
pull bot pushed a commit to sonvt1710/terminal that referenced this issue Aug 8, 2022
While working on microsoft#13398 I felt that `TSFInputControl` wasn't up to sniff.
This commit is a minor cleanup of the class:
* default member initializers
* Simplified use of STL classes which already perform boundary checks
* Correctly check text buffer emptiness in `_SendAndClearText`
* Track selection range as mandated by the API

## Validation Steps Performed
* Japanese IME (Full-Width Katakana)
  Typing "saitama" produces "サイタマ" ✅
* Korean IME
  Typing "gksrmf" produces "한글" ✅
* Vietnamese IME
  Typing "xin chaof" continues to produce broken "xin xinchaof"
  (It's supposed to produce "xin chào")
* Emoji Picker (Win+.)
  ✅
@ghost ghost closed this as completed in #13678 Aug 11, 2022
@ghost ghost closed this as completed in ed800dc Aug 11, 2022
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Aug 11, 2022
@zadjii-msft zadjii-msft removed the Needs-Discussion Something that requires a team discussion before we can proceed label Aug 15, 2022
@ghost
Copy link

ghost commented Aug 17, 2022

🎉This issue was addressed in #13678, which has now been successfully released as Windows Terminal Preview v1.15.228.:tada:

Handy links:

@rabianr
Copy link
Author

rabianr commented Aug 20, 2022

I'm sorry for bringing this up again.
Thanks to the commit #13678, the original issue is fixed in the latest version.
But recently, I've found that the new behavior is not very desirable. At least for me.
For example, when I'm in the middle of editing something in Hiragara mode then switch to a different application or make the Terminal lose focus. Then when the Terminal get focus again, the IME's input mode will be switched to Half-width alphanumeric.
It's not a bug, but kind of inconvenience. So may I request a setting to disable the new behavior?

v1.13.10983.0
terminal-1 13

v1.15.2282.0
terminal-1 15

I don't have other CJK languages installed, so it might happen with the Japanese MS IME only.

Also, I believe that the new behavior is causing alt + shift to not retaining the last used input mode as mentioned in #13681.

v1.13.10983.0
terminal-1 13-2

v1.15.2282.0
terminal-1 15-2

PKRoma pushed a commit to PKRoma/Terminal that referenced this issue Oct 15, 2022
While working on microsoft#13398 I felt that `TSFInputControl` wasn't up to sniff.
This commit is a minor cleanup of the class:
* default member initializers
* Simplified use of STL classes which already perform boundary checks
* Correctly check text buffer emptiness in `_SendAndClearText`
* Track selection range as mandated by the API

## Validation Steps Performed
* Japanese IME (Full-Width Katakana)
  Typing "saitama" produces "サイタマ" ✅
* Korean IME
  Typing "gksrmf" produces "한글" ✅
* Vietnamese IME
  Typing "xin chaof" continues to produce broken "xin xinchaof"
  (It's supposed to produce "xin chào")
* Emoji Picker (Win+.)
  ✅

(cherry picked from commit 2c922e1)
Service-Card-Id: 85034073
Service-Version: 1.15
PKRoma pushed a commit to PKRoma/Terminal that referenced this issue Oct 15, 2022
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+.)
  ✅

(cherry picked from commit ed800dc)
Service-Card-Id: 84832470
Service-Version: 1.15
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.