Fix bug of some IMEs cannot input in terminal#3251
Fix bug of some IMEs cannot input in terminal#3251Tyriar merged 4 commits intoxtermjs:masterfrom Python-37:Fix-bug-of-some-IMEs-cannot-input-in-terminal
Conversation
Fix bug of QQ pinyin and Rime IME cannot input characters in terminal.
|
Cool! :XD |
Tyriar
left a comment
There was a problem hiding this comment.
Great work all!
The fix seems a little strange, I can understand if the IME sees a 0x0 element and doesn't work, but the textarea should not be 0x0 but the size of the cursor:
Can you check the size of the textarea on your machine? It's seems really strange that padding would affect an IME like this.
cc @rebornix
|
@Tyriar As our previous test, when the padding is 0, the textarea's width is also 0 when typing; but when it finishes, the input words are held on the textarea (can be verified by logging its value), and it's width is not 0, but the text width. I just record its behavior from a VM, if you need it. textarea-style.mp4BTW I also record a video logging its value when keydown-event.mp4As our previous test, the IME will hold inputs until it finishes, then the IME will send the final result to the program. But it's unsure that when it finishes, the final result will be kept in the textarea, and Xterm doesn't put them out. Say if you type Updated: When I remove the style keydown-event-default-padding.mp4(Sorry the VM's performance is not good, so the video is not that smooth) Updated: reorganize my word. |
|
Sorry for the regression, I didn't noticed the issue is happening until now. The PR simply reverts IME input issue is caused from Note 1: To me, this fix looks kind of a workaround, since I think css should not affect functional behavior. We might need further investigation for the issue as an another task. (I don't have time to do that right now though.) |
|
@kena0ki Maybe another option is setting min-width-rime.mp4 |
|
@ccloli I confirmed Edit: |
|
@kena0ki some css properties are calculated and overridden by javascript methods, see : /src/browser/input/CompositionHelper.ts. we should notice this. |
Yep, the width is probably calculated by JS, it looks like the width is calculated by trimmed text's width, so when it only has a whitespace, its width becomes 0.
When I was testing, I encountered this, too. However I can't reproduce it now, but I guess it's due to the position of the textarea is out of the browser's viewport.
It behaves like this, but from my test it might not be IME's issue, since you can typing text in a zero-width textarea with these IMEs and having no issue, the inputs goes into the textarea and doesn't loss any characters. (However if you click the textarea to input, if you've already type some text on it, some of text may be replaced, but clicking Focus button won't have the issue. Maybe when width goes zero, some of text is selected, so when typing it'll be replaced) <body>
<textarea placeholder="type here" style="border: 0px; padding: 0px; margin: 0px; width: auto; height: 89px;" onfocus="this.style.width = 0" onblur="console.log(this.value); this.style.width = 'auto';"></textarea>
<button onclick="document.querySelector('textarea').focus()">Focus</button>
</body> |
|
Ah, I understand. Losing focus cause the issue. |
|
What if we did this instead? // Ensure the text area is at least 1x1, otherwise certain IMEs may break
this._textarea.style.width = Math.max(compositionViewBounds.width, 1) + 'px';
this._textarea.style.height = Math.max(compositionViewBounds.height, 1) + 'px';If someone could test that before the coming Monday I can push this in for VS Code 1.55 |
|
I change the built code directly, having no issue. math-max-1.mp4 |
|
should we start a new PR? |
|
Thanks for the quick tests! I made the change in this PR |
|
@Tyriar Hooray! |
| this._textarea.style.width = compositionViewBounds.width + 'px'; | ||
| this._textarea.style.height = compositionViewBounds.height + 'px'; |
There was a problem hiding this comment.
| this._textarea.style.width = compositionViewBounds.width + 'px'; | |
| this._textarea.style.height = compositionViewBounds.height + 'px'; |
Shouldn't this 2 lines be removed?

Fix bug of QQ pinyin and Rime IME cannot input characters in VS Code's terminal.
microsoft/vscode#115814
This bug behaves like this microsoft/vscode#115814 (comment)
Here we found the reason microsoft/vscode#115814 (comment)
Here we found a solution microsoft/vscode#115814 (comment)
The css
padding: 0caused this bug.Thanks to @ccloli and @ZhyMC