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

(WIP) Reset to alphabet input mode on <Escape> or <Enter> key #15590

Closed
wants to merge 22 commits into from

Conversation

qqkookie
Copy link

@qqkookie qqkookie commented Jun 22, 2023

Summary of the Pull Request

When pressing <Escape> or <Enter> key, reset (CJK) keyboard IME input state to alphabet input mode.

References and Relevant Issues

Adds new feature:
#1304 Feature Request: IME mode after pressing Escape or Enter key in CJK input.

Detailed Description of the Pull Request / Additional comments

  • Use case: CJK user types shell command line using CJK input IME, or edits text file using Linux text editors like Vim (vi), nano or emacs editor.
  • Problem: After typing CJK words and phrases in CJK-script composition mode, user have to manually exit CJK input mode by pressing the composition key again and return to alphabet input mode. All shell commands and editor commands are alphabet/English word or key. So, CJK input after <Escape> or <Enter> key always causes command error. It is very error-prone and very, very annoying.
  • Solution: This PR solves such annoyance by switching IME input mode to alphabet input mode automatically upon pressing <Escape> or <Enter> key. This can be turned on/off at terminal/interaction setting pane.
  • Caveats: To type multi-line CJK phrases, user have to press CJK composition key after pressing each <Enter> key to go next line.
  • TODO: Setting toggle switch works as expected. Done.

Validation Steps Performed

This feature is widely supported in many open-source or commercial CJK-aware terminal emulator/SSH/Telnet client software or editors like Korean-localized xterm, hanterm, iPuTTY, XShell, and some MinTTY. It is such universally requested feature for Korean command line users.

PR Checklist

qqkookie and others added 14 commits June 20, 2023 14:41
"src/terminal/input/terminalInput.cpp" : TerminalInput::HandleKey()
"src/terminal/input/terminalInput.cpp" : TerminalInput::HandleKey()
TODO: Apply globals.KeyAlphaMode setting to  TerminalInput::CheckAlphaMode()
TODO: Apply globals.KeyAlphaMode setting to  TerminalInput::CheckAlphaMode()
Don't exclude nuget `packages/` in vscode. Excluding via `file.exclude`
also excludes them from c++ language extension's `includePath` and
generates missing include files and header errors.

We might still like to exclude them from full text search, so we do it
using `search.exclude`.

Closes microsoft#15578
This PR adds a `searchWeb` command to search the selected text on the web.
Arguments:
- `queryUrl`: URL of the web page to launch (the selected text will be
inserted where the first `%s` is found in the query string)

To make the search text more "compact" and handle multi-line selections,
I'm concatenating the selected lines and replacing consecutive
whitespaces with a single space (we may change this with something more
clever in case).

## Validation Steps Performed
Manual testing with single, multi-line, block selections.

Closes microsoft#10175

---------

Co-authored-by: Marco Pelagatti <marco.pelagatti@iongroup.com>
Co-authored-by: Mike Griese <migrie@microsoft.com>
…osoft#15582)

As a shortcut, GetLastNonSpaceCharacter can start with the last
committed row. It's guaranteed that there isn't anything of worth below
that point, so why bother checking?

Without this, Terminal immediately commits the entire 9031-line buffer
on startup while trying to--get this!--clear the screen!

---------

Co-authored-by: Leonard Hecker <lhecker@microsoft.com>
…5568)

I originally intended to add the Drop Validator (which is a compliance
requirement) task to the build, but I quickly realized that we weren't
generating a complete SBOM manifest covering every artifact that we
produced.

We were generating the SBOM manifest, and then re-packing the Terminal
app which very likely invalidated all of the hashes and signatures in
the SBOM manifest!

We were also missing the unpackaged build.

I've removed the `appx-PLATFORM-CONFIG` and `unpackaged-PLAT-CONF`
artifacts and combined them into a single one, `terminal-PLAT-CONF`.
TODO: Apply globals.KeyAlphaMode setting to  TerminalInput::CheckAlphaMode()
@github-actions

This comment has been minimized.

@qqkookie
Copy link
Author

@microsoft-github-policy-service agree

@qqkookie qqkookie changed the title Kookie (WIP) Reset to alphabet input mode on <Escape> or <Return> key Jun 22, 2023
@qqkookie qqkookie changed the title (WIP) Reset to alphabet input mode on <Escape> or <Return> key (WIP) Reset to alphabet input mode on <Escape> or <Enter> key Jun 22, 2023
@DHowett
Copy link
Member

DHowett commented Jun 22, 2023

Thanks for submitting this! I have a couple architecture concerns. I have not reviewed the code in-depth yet, sorry.

In our project, the TerminalInput module is used to translate Console Key events into VT (so, VK_RIGHT becomes ^[ [ C, as well as a bunch of other things.)

It is supposed to be relatively well-contained and not call out to the OS or support any user configuration.

This is because TerminalInput is also used in the Windows Console Host (conhost) and on OneCore/NanoServer, two very minimal versions of Windows with no dependencies.

For Windows Terminal, the right place to change the input behavior is on the TerminalCore or TerminalControl projects. Keeping your input behavior changes in the src/cascadia directory tree will make sure that they do not impact the Windows Console Host or NanoServer. 😄

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Task It's a feature request, but it doesn't really need a major design. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Jun 24, 2023
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@qqkookie
Copy link
Author

Why some check is failing (PowerScipt fail? What is it?) and some checks take so long? Over a days pass and still in progress. :( Should I re-commit to start over?

@lhecker
Copy link
Member

lhecker commented Jun 26, 2023

The code formatting check failed. If you open PowerShell inside the terminal project you can execute these two lines:

Import-Module .\tools\OpenConsole.psm1
Invoke-CodeFormat

@lhecker
Copy link
Member

lhecker commented Jun 26, 2023

I'd also be happy to fix the PR's coding style for you. 🙂 If you'd be fine with that, just let me know once you feel like this PR works correctly for you.

@DHowett Can you check your mails, if you ever got a response to your IMM/CoreText questions (#1304 (comment))?

Import-Module .\tools\OpenConsole.psm1
Invoke-CodeFormat
done
@qqkookie
Copy link
Author

The code formatting check failed. If you open PowerShell inside the terminal project you can execute these two lines:

Import-Module .\tools\OpenConsole.psm1
Invoke-CodeFormat

Thank you for kindly help.

I'd also be happy to fix the PR's coding style for you. 🙂 If you'd be fine with that, just let me know once you feel like this PR works correctly for you.

@DHowett Can you check your mails, if you ever got a response to your IMM/CoreText questions (#1304 (comment))?

I haven't receive any response on that.
I am new to here. Your help will be always welcome and appreciated. :)

Now all check is passed and what should I do next?
How can I turn draft PR to normal PR? Ready for review?

@qqkookie qqkookie marked this pull request as ready for review June 26, 2023 12:24
@lhecker
Copy link
Member

lhecker commented Jun 26, 2023

Now all check is passed and what should I do next?

FYI it might take a little while to get this PR merged and shipped. One of the main developers of Windows Terminal is currently out of office and we still need to properly test it. It'll then ship in the next preview version (1.19) in a month or so. I'm sorry for the wait!

@cmplstofB
Copy link

How about a proposal mentioned here? --- to be able to interpret the escape sequence controlling the IME which had already implemented by several other terminal software.
The implementation might be a bit complicated, but this method --- the Windows Terminal only provides IME control features and each shell or editor etc actually uses it in its own way --- will give users a more flexible way to switch IME state as there wish.

@qqkookie
Copy link
Author

qqkookie commented Jul 5, 2023

How about a proposal mentioned here? --- to be able to interpret the escape sequence controlling the IME which had already implemented by several other terminal software. The implementation might be a bit complicated, but this method --- the Windows Terminal only provides IME control features and each shell or editor etc actually uses it in its own way --- will give users a more flexible way to switch IME state as there wish.

Such feature is separate feature from automatic IME handing of this PR, not alternative of each other, IMHO.

Such feature is to let client program or remote app (like Vim editor or cmd.exe/shell ) can control the user-side local IME of terminal emulator by sending such control sequence. For example, editor can set IME off on command mode. But it requires support from the editor itself.

If many shell/editor application request/support such feature, such IME-controlling control-sequence processing can be implemented with IMM routines, if needed.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structurally, this seems mostly good. I'd have probably wrapped the IMM support into a helper class / struct (rather than just some global statics), but that's minor.

I'd probably want to double-check this UX with some of our other IME experts, but I'd need to find them first 😛 If there's existing precedent for this kind of behavior, and it's toggleable with a setting, then I'd be hard pressed to say no

@zadjii-msft zadjii-msft added the Needs-Discussion Something that requires a team discussion before we can proceed label Jul 13, 2023
@KalleOlaviNiemitalo
Copy link

I won't be reviewing this.

@zadjii-msft
Copy link
Member

quick notes from the discussion we had:

  • making this a setting is great. If this breaks someone's workflow, well, they don't need to turn it on 😉
  • Technically, the Terminal is already pre-loading the IMM dll immediately on startup, but it's probably good to wrap this code in delayloads anyways. Maybe someday a dependnecy won't pull it in automatically, so this would be helpful to have then.
  • We're a little worried that mixing and matching the raw IMM functions with the WinRT ones (used in TSFInputControl, see CoreTextEditContext) might not work as expected. We wanted to validate with someone who might know the internals better (though, we don't know who that is).
  • we didn't really come to a name consensus. alphaKbdOnEsc is certainly better, but something more semantic like resetToAlphaKbdMode or something. We probably need to discuss more.

Thanks for bearing with us while we sort this out!


addenda: we also discussed how we really need to get our IME support figured out by an expert. Cases in point: this thread, #13681, #14407 and the long list of issues before those.

@lhecker lhecker added this to the Terminal v1.19 milestone Jul 24, 2023
@lhecker lhecker removed the Needs-Discussion Something that requires a team discussion before we can proceed label Jul 24, 2023
@zadjii-msft
Copy link
Member

@lhecker did this get obsoleted by your IME rewrite?

@lhecker
Copy link
Member

lhecker commented Apr 29, 2024

Oh, yes it did! @qqkookie Thank you so much for the PR, but you've probably already seen my update in the corresponding issue. The new IME rewrite should be much more robust in general.

@lhecker lhecker closed this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: IME mode after pressing Escape or Enter key in CJK input
8 participants