gencay / vscode-chatgpt

An unofficial Visual Studio Code - OpenAI ChatGPT integration
ISC License
3.5k stars 760 forks source link

Add isComposing check to keydown event for users using Japanese IME with Kanji characters #191

Closed katsumi-axis closed 1 year ago

katsumi-axis commented 1 year ago

I am a user of GitHub and I use a Japanese IME to input Kanji characters. However, I noticed that when using the keydown event in JavaScript, it does not always capture the correct input due to the way that the IME works.

I suggest adding an isComposing check to the keydown event, which will improve the accuracy of input detection for users using Japanese IME with Kanji characters. This will ensure that the event is only triggered once the user has finished composing their input.

Here is an example of the code modification that would need to be made:

document.addEventListener('keydown', function(e) {
  if (!e.isComposing) {
    // Perform action when input is finished composing
  }
});

I believe that this improvement would benefit many users who use a Japanese IME and would greatly improve their experience with GitHub. Thank you for considering this suggestion.

gencay commented 1 year ago

@katsumi-axis thanks for the suggestion. I am not familiar with the isComposing attribute, is that a common way to fix the issues with such keyboards?

katsumi-axis commented 1 year ago

@gencay There are many ways to do it, but given that an API is provided, it seems like one correct implementation method. https://www.stum.de/2016/06/24/handling-ime-events-in-javascript/

harley005 commented 1 year ago
document.getElementById('question-input').addEventListener("keydown", function (event) {
    if (event.key == "Enter" && !event.shiftKey && !event.isComposing) {
        event.preventDefault();
        addFreeTextQuestion();
    }
});

@gencay modify media/main.js just like this code. Thank you for the great work.

gencay commented 1 year ago

@harley005 @katsumi-axis please check out the v3.9.5 on marketplace. This should now be fixed. Could you confirm?

harley005 commented 1 year ago

@harley005 @katsumi-axis please check out the v3.9.5 on marketplace. This should now be fixed. Could you confirm?

@gencay It's work, thank you!

katsumi-axis commented 1 year ago

@gencay I confirm it, Thank you for your great work.