Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim extension issue with Chinese IME #8133

Closed
localvar opened this issue Jun 25, 2016 · 13 comments
Closed

vim extension issue with Chinese IME #8133

localvar opened this issue Jun 25, 2016 · 13 comments
Assignees
Labels
feature-request Request for new features or functionality *question Issue represents a question, should be posted to StackOverflow (VS Code) VIM VIM issue
Milestone

Comments

@localvar
Copy link

  • VSCode Version: 1.2.1
  • OS Version: Windows 10 professional

I tried two Vim extensions, amVim and VsCodeVim, both have problems when using Chinese IME:

from the comments of the issues: it is not only affect Windows, but also OSX and Linux; and not only Chinese, but also Japanese.

So, it is highly suspect this is an issue of VSC instead of the extensions.

@rebornix
Copy link
Member

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.

@fenbox
Copy link

fenbox commented Jul 8, 2016

Hope this can fix soon, it's terrible for Chinese (reference above)

@freshcn
Copy link

freshcn commented Jul 8, 2016

+1

@Yukaii
Copy link
Contributor

Yukaii commented 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
Copy link
Member

rebornix commented Jul 8, 2016

@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
Copy link
Member

alexdima commented Jul 8, 2016

@localvar @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:
vim

Please note that his works by overwriting the built-in command replacePreviousChar and then delegating back to it as needed. See here

@alexdima
Copy link
Member

alexdima commented 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
Copy link
Member

alexdima commented 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.

@alexdima alexdima added the VIM VIM issue label Jul 8, 2016
@Yukaii
Copy link
Contributor

Yukaii commented Jul 8, 2016

@rebornix you're right, I found Pinyin IM breaks normal mode as you described, Zhuyin IM also has some problems:

edc97645-c6a2-4fa1-b3e2-dc06f8ad2b43-69456-00017ae0ba8a6e64

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
Copy link
Member

@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.

@alexdima alexdima added this to the Backlog milestone Jul 11, 2016
@alexdima alexdima added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Jul 11, 2016
@rebornix
Copy link
Member

@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

  1. Open a file
  2. Use English IME
  3. Type a
  4. The Vim mode should be switched to Insert Mode immediately. It's not related to any key strokes after.

Then use Chinese IME

  1. Open a file
  2. Use Chinese IME
  3. Type a
  4. 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

  1. Open a file and the Vim Mode is Normal
  2. Use Chinese IME
  3. Type an
  4. 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

  1. Switch to Insert Mode (because the first char is a)
  2. 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.

@alexdima
Copy link
Member

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:

  • input
  • compositionstart
  • compositionupdate
  • compositionend

We 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#L114

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.

@alexdima alexdima modified the milestones: July 2016, Backlog Jul 12, 2016
@alexdima alexdima added the feature-request Request for new features or functionality label Jul 15, 2016
@alexdima
Copy link
Member

alexdima commented Jul 15, 2016

Here is an example how to use the new compositionStart and compositionEnd:

alexdima/vscode-vim@2c1ccd7

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.

@rebornix rebornix mentioned this issue Jul 20, 2016
4 tasks
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality *question Issue represents a question, should be posted to StackOverflow (VS Code) VIM VIM issue
Projects
None yet
Development

No branches or pull requests

7 participants