Open tamuratak opened 1 month ago
Hi thank you for filing this issue. This actually seems to happen also when the setting is disabled, so it used to happen before too. Just a question, what would you expect to happen instead? When you focus on the VS Code window again and press space, do you expect a space to just be added and the composition to not continue?
This also happens on insiders.vscode.dev on higher chromium versions. I am wondering if this is a bug though. It seems to me this behavior could be correct, because you cycle through the IME by pressing space, but you have not yet chosen a final composition (by pressing Enter). So when you go to another tab and you come back, the composition is still underway until you choose a final composition, so pressing space just gets you cycling back through the composition again.
https://github.com/user-attachments/assets/783afe85-dded-45fe-902f-ae4e80f83731
In fact the same happens when you type sennsei
into a chrome input, press space, click on another one, then focus the first one again and press space. The input in the first chrome tab restarts composition again.
https://github.com/user-attachments/assets/3174c23e-4e2d-4e50-8e18-58845981870d
I am testing the composition some more. Do you by any chance mean that when you move back to the VS Code window, the previous composition should be highlighted and pressing space should modify the previous composition instead of starting a new one?
After some more investigation this seems to happen because we update the edit context at the end of the typing event and in fact when the text update event sends an event:
text: せんせい updaterangestart : 0 updaterangeend : 4
We update the edit context ultimately to:
editContext.text : せんせい editContext.selectionStart : 4 editContext.selectionEnd : 4
We do this so that the editor selection is synchronized with the EditContext selection. If we don't do this, it leads to issues with custom registered typing commands as well as problems in IME.
Now when the composition ends, we are in the state above.
Now when composition starts we are in the following state as above.
editContext.text : せんせい editContext.selectionStart : 4 editContext.selectionEnd : 4
Then we receive a text update event:
text : 先生 selectionstart : 4 selectionend : 6 updaterangeend : 4 updaterangestart : 4
It looks like the next text update event suggests to replace the text to 先生, but because our selection was (4, 4) not (0, 4), the text is instead inserted at the end of that line instead of replacing the composition.
The question is why does chromium send this text update event if it is clear that we no longer have the composition selected? I will file a ticket to the chromium team to discuss this with them.
I opened an issue here for the chromium them: https://issues.chromium.org/issues/369883717
I will wait until they respond. If they mention this is not a bug, or not something they will fix, we will have to rethink how editing is done to fix this problem.
Version: 1.94.0-insider Commit: c43f508b732d24b0c4732de9db2b38b4c5b88b8a Date: 2024-09-26T05:04:07.935Z Electron: 30.5.1 ElectronBuildId: 10262041 Chromium: 124.0.6367.243 Node.js: 20.16.0 V8: 12.4.254.20-electron.0 OS: Darwin arm64 22.6.0
Steps to Reproduce:
"editor.experimentalEditContextEnabled": true
sennsei
Space
Space
.https://github.com/user-attachments/assets/ac535f45-c851-49df-8735-04aa6e793454