maebert / themostdangerouswritingapp

If you stop typing for more than five seconds, all progress will be lost.
https://maebert.github.io/themostdangerouswritingapp
GNU General Public License v3.0
1.75k stars 282 forks source link

When I type in Chinese characters, the browser cannot count #37

Open agreadname opened 5 years ago

agreadname commented 5 years ago

It's so funny and useful tools,I want to share to more friend,so I hope you can resolve this issues

maebert commented 5 years ago

Thanks for bringing this up!

To be honest I'm woefully ignorant about CJK input methods, but this is a great opportunity to learn. I'll look into it when I have a bit of time!

YoukouTenhouin commented 4 years ago

As a Chinese IME user, I would like to provide some insight into the cause of this bug.

First, some knowledge about how CJK input works:

CJK languages have thousands of commonly used characters, but our keyboard has only about 100 keys available. Thus, we use something called IME (Input Method Editor), which is a software responsible for mapping a stream of keystrokes into another stream of characters.

Basically, it works like this:

  1. When an IME is enabled, it will intercept keystrokes made by the user, and store them input a buffer. The original keystrokes may or may not reach the destinate input control, depend on IME used.

  2. The IME find all strings that can be mapped to the keystrokes, and display them in a candidate list for the user to choose, as most of the time more than one string can be mapped to the input.

  3. When the desired candidate has been chosen, the IME will submit the candidate into destinate input control all at once.

Be aware that we usually input on a string-by-string basis, rather than char-by-char, which is different from alphabet-based language users.

So the problem is this application resets its timer in the onKeyDown callback, which is unfortunately very unreliable to CJK editing (since keystrokes are handled by the IME rather than input control).

I think if we reset the timer in the onChange callback would improve the situation a little bit, but I don't think that is the ideal solution since more problems will arise:

So I don't really have an idea now. I don't know how to capture keystrokes when there is an IME active, and I'm not even sure such a method even exists. Maybe the best we can do now is to add some configurable workarounds for CJK users?

whuter commented 4 years ago

@AraragiHokuto We could use the compositionupdate event, which can capture the inputs in IME. Another question is that it's unsuitable to count the words by white spaces in Chinese articles, and I would like to fix it.