You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason this issue comes with Vim extensions is because Vim needs to monitor user's keyboard input and all these extensions are listening to type command, but it's working in a strange way.
Let's say users want to type in a Chinese word 安 and in Chinese IME, they should type a + n then in their IME popup window, choose the first word by pressing 1 or space. Currently if you monitor type command, only a is emitted by VS Code.
So ideally, if users type an1 in Chinese IME, VS Code should only pass 安 to type command listeners.
Yukai Huang (@Yukaii) are you saying Chinese works perfectly using vimStyle even with steps I mentioned above? Not sure if I set up wrong things, but I just installed latest version of vimStyle and tried to type 安 in normal mode, and the vim mode breaks.
Peng Lyu (@rebornix) you're right, I found Pinyin IM breaks normal mode as you described, Zhuyin IM also has some problems:
I input "可動" these two word in normal mode and it insert correctly, but when I only type one Zhuyin phonetic character "ㄎ", and press enter, it replace first word "可".
alexandrudima oh man, you helped all Chinese Vim users out. replacePreviousChar is exactly what we need to handle CJK IME without breaking the Vim Mode.
alexandrudima played with this API and I found that current information is not enough yet. A really simple example:
First, below is what will happen when we use Vim with English IME
Open a file
Use English IME
Type a
The Vim mode should be switched to Insert Mode immediately. It's not related to any key strokes after.
Then use Chinese IME
Open a file
Use Chinese IME
Type a
Our extension (VSCodeVim or alexandrudima 's Vim)'s type command handler will be invoked, and args: {text: 'a'} is passed to it. At the same time, replacePreviousChar is still not invoked.
Here comes the problem, since we are using Chinese IME, this a might be replaced by a Chinese character later. But if we are using English IME, we should translate this a to Switch Mode to Insert Mode. In type command handler, we have no idea about the IME info so we don't know how to handle this a correctly.
Another funny example with Chinese IME is
Open a file and the Vim Mode is Normal
Use Chinese IME
Type an
A popup window shows up and provides several possible Chinese characters we want to type in.
If we type 1, Chinese IME will pick up the first Chinese character listed in the popup. And we will get a replacePreviousChar event, the args passed in is {text: '安', replaceCharCnt: '2'}. However, if we press Enter key, we will get a replacePreviousChar with {text: 'an', replaceCharCnt: '2'} . The expected way of handing this an in Vim is
Switch to Insert Mode (because the first char is a)
Insert n.
You may already see the problem, when we get the replacePreviousChar event with arguments {text: 'an', replaceCharCnt: '2'}, we have no idea that whether we should replace previous characters with an or translating them to switch to Insert Mode then insert 'n'. Again, that's because we are lack of the information of IME.
Personally I think it's not a good idea to detect IME info ourselves because we will end up moving the same logic of VS Code to the extension.
So far I have found that these two primitives: type and replacePreviousChar were sufficient, but I understand your problem too, especially in normal mode, where the receival of type: a could be a part of building a complex Chinese word or it could be the actual typed a. And once you've made a decision to go into append mode, replacePreviousChar is not really useful.
I will investigate if we can enrich type and replacePreviousChar, otherwise we might end up exposing something different to help in the normal mode case.
The idea is you can overwrite (similar to type and replacePreviousChar) two more -- compositionStart and compositionEnd. These two new ones should help in distinguishing the composition case vs non-composition case.
Activity
rebornix commentedon Jun 25, 2016
The reason this issue comes with Vim extensions is because Vim needs to monitor user's keyboard input and all these extensions are listening to
typecommand, but it's working in a strange way.Let's say users want to type in a Chinese word
安and in Chinese IME, they should typea+nthen in their IME popup window, choose the first word by pressing1or space. Currently if you monitortypecommand, onlyais emitted by VS Code.So ideally, if users type
an1in Chinese IME, VS Code should only pass安totypecommand listeners.fenbox commentedon Jul 8, 2016
Hope this can fix soon, it's terrible for Chinese (reference above)
freshcn commentedon Jul 8, 2016
+1
Yukaii commentedon Jul 8, 2016
vimStyle works with Chinese
VSC: 1.3.0
OS: Mac OS X El Capitan
Tested with Default Zhuyin IM & Squirrel IM
rebornix commentedon Jul 8, 2016
Yukai Huang (@Yukaii) are you saying Chinese works perfectly using vimStyle even with steps I mentioned above? Not sure if I set up wrong things, but I just installed latest version of vimStyle and tried to type
安in normal mode, and the vim mode breaks.alexdima commentedon Jul 8, 2016
Bomin Zhang (@localvar) Peng Lyu (@rebornix) I am sorry my VIM sample contained a typo that was causing IME to fail when in insert/append mode:
See alexdima/vscode-vim@708d4c0
After that change here is IME in insert mode with my VIM sample:

Please note that his works by overwriting the built-in command
replacePreviousCharand then delegating back to it as needed. See herealexdima commentedon Jul 8, 2016
Please also note that my sample does not support IME building in normal mode because I am lazy and didn't do it, but not because it could not be possible.
alexdima commentedon Jul 8, 2016
Also, possible causes for different behaviour in 1.2.1 could be the PR #5615 -- but IMHO the PR is quite good.
Yukaii commentedon Jul 8, 2016
Peng Lyu (@rebornix) you're right, I found Pinyin IM breaks normal mode as you described, Zhuyin IM also has some problems:
I input "可動" these two word in normal mode and it insert correctly, but when I only type one Zhuyin phonetic character "ㄎ", and press enter, it replace first word "可".
rebornix commentedon Jul 10, 2016
alexandrudima oh man, you helped all Chinese Vim users out.
replacePreviousCharis exactly what we need to handle CJK IME without breaking the Vim Mode.rebornix commentedon Jul 12, 2016
alexandrudima played with this API and I found that current information is not enough yet. A really simple example:
First, below is what will happen when we use Vim with English IME
aThen use Chinese IME
atypecommand handler will be invoked, andargs: {text: 'a'}is passed to it. At the same time,replacePreviousCharis still not invoked.Here comes the problem, since we are using Chinese IME, this
amight be replaced by a Chinese character later. But if we are using English IME, we should translate thisatoSwitch Mode to Insert Mode. Intypecommand handler, we have no idea about the IME info so we don't know how to handle thisacorrectly.Another funny example with Chinese IME is
anIf we type
1, Chinese IME will pick up the first Chinese character listed in the popup. And we will get areplacePreviousCharevent, the args passed in is{text: '安', replaceCharCnt: '2'}. However, if we press Enter key, we will get areplacePreviousCharwith{text: 'an', replaceCharCnt: '2'}. The expected way of handing thisanin Vim isa)n.You may already see the problem, when we get the
replacePreviousCharevent with arguments{text: 'an', replaceCharCnt: '2'}, we have no idea that whether we should replace previous characters withanor translating them toswitch to Insert Mode then insert 'n'. Again, that's because we are lack of the information of IME.Personally I think it's not a good idea to detect IME info ourselves because we will end up moving the same logic of VS Code to the extension.
alexdima commentedon Jul 12, 2016
I will investigate further in our code-base, but beware that we don't have any input building (IME) logic either, Chrome does that.
We take the "lower-level" events:
inputcompositionstartcompositionupdatecompositionendWe then do quite some computation to eliminate the text we have previously placed in the
<textarea>for screen readers and to accommodate different browsers and then we deduce what was the diff (what was actually typed). https://github.com/Microsoft/vscode/blob/master/src/vs/editor/common/controller/textAreaHandler.ts#L114So far I have found that these two primitives:
typeandreplacePreviousCharwere sufficient, but I understand your problem too, especially in normal mode, where the receival oftype: acould be a part of building a complex Chinese word or it could be the actual typeda. And once you've made a decision to go into append mode,replacePreviousCharis not really useful.I will investigate if we can enrich
typeandreplacePreviousChar, otherwise we might end up exposing something different to help in the normal mode case.alexdima commentedon Jul 15, 2016
Here is an example how to use the new
compositionStartandcompositionEnd:alexdima/vscode-vim@2c1ccd7
The idea is you can overwrite (similar to
typeandreplacePreviousChar) two more --compositionStartandcompositionEnd. These two new ones should help in distinguishing the composition case vs non-composition case.Fixes microsoft#8133: Expose overwritable commands `compositionStart`…