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

[BUG] Problems handling the Enter key in a prompt textbox in languages other than English #277

Open
tokawa-ms opened this issue Mar 5, 2025 · 1 comment
Labels
🐛bug Something isn't working

Comments

@tokawa-ms
Copy link

tokawa-ms commented Mar 5, 2025

Describe the bug
This is a problem report about a one-line text box for prompt input, such as on the "Generate Text" screen.

When entering a language other than English (such as Japanese) in this text box, the generation process is called because it is mistakenly judged that prompt input is completed while the character string is being entered.

To Reproduce
Requirements :

  1. Japanese or other IMEs available in Windows environments

Steps to reproduce the behavior:

  1. Go to 'Generate Text'
  2. Enable IME
  3. Type some charactors
  4. Confirm the conversion candidate with the Enter key
  5. Even though I'm in the middle of a sentence, GenerateText is called.

Expected behavior

  • The ENTER keystroke to confirm the conversion of an IME does not invoke the generation process.
  • When you complete the input of a sentence, a single Enter key is used to invoke the generation process.

Please complete the following information:

  • App Version : Version 0.3.6.0 from Microsoft Store and Latest Build from GitHub main branch.

Additional context
The reason for this is that in languages other than English, you press the Enter key to confirm the IME conversion.
The current logic is to call the generation process (e.g. GenerateText() method) whenever there is an Enter key input after a character is entered in TextBox.
However, if we are considering IME conversion, we should add an implementation that ignores the IME conversion confirmation Enter.

I have an idea to solve this problem.

Because the KeyDown event does not occur during IME input, it can be determined that the IME is being entered when the Enter key has not been entered in the previous KeyDown event. By adding this condition to the KeyUp event handler, it is possible to ignore Enter when the IME conversion is confirmed and call the generation process only with Enter when the string input is completed.

For example, I have been able to confirm that if I rewrite the event handler of the TextBox in Generate.xaml.cs as follows, it behaves as expected:

    private bool isImeActive = true;
    private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == Windows.System.VirtualKey.Enter && sender is TextBox && isImeActive == false)
        {
            if (InputTextBox.Text.Length > 0)
            {
                GenerateText(InputTextBox.Text);
            }
        }

        isImeActive = true;
    }

    private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == Windows.System.VirtualKey.Enter)
        {
            isImeActive = false;
            e.Handled = true;
        }
    }

There might be a better way, so I've filed an issue once, but if you like, I can add this implementation to the TextBox where the behavior occurs and make it a pull request.

@tokawa-ms tokawa-ms added the 🐛bug Something isn't working label Mar 5, 2025
@nmetulev
Copy link
Member

nmetulev commented Mar 6, 2025

Hi @tokawa-ms, thank you for creating an issue and identifying the solution. Please feel free to submit a pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants