Hi Björn, On Fri, Aug 28, 2009 at 2:40 AM, björn<[email protected]> wrote: >> Case of checking IM state before/after ESC key: >> before: IM switch(off>on) > check IM state(on) > handle key > save >> iminsert(on) >> after : IM switch(off>on) > handle key > save iminsert(off) > check IM >> state(on) >> I expected _before_ behavior. > Sorry, I don't understand the "before" and "after"?
I will explain it. But, first, please let me know what will happen with the
following instructions in snapshot 49 or later.
1. :set noimdisable
2. enter insert mode
3. switch IM using IM icon in OS X's menu bar
4. input text with IM
(Swedish characters, Japanese characters, Hangle characters or something)
5. press ESC key
6. enter insert mode
7. input text with IM
8. disable IM using IM icon in OS X's menu bar
9. input ASCII text
10. press ESC key
11. enter insert mode
12. you can input text "without" IM?
I have tried it in snapshot 49 without any vimrc/gvimrc/plugins.
1. :set noimdisable
2. enter insert mode
3. switch IM using IM icon in OS X's menu bar
4. input text with IM
5. press ESC key
6. enter insert mode
7. input text with IM
8. disable IM using IM icon in OS X's menu bar
9. input ASCII text
10. press ESC key
11. enter insert mode
12. I input text "with" IM.
I expected that I can input text "without" IM in 12.
> You have moved code from from activateIm to checkImState, but this
> makes absolutely no sense to me. Please explain. Why do you need to
> send the ActivateImMsgID to Vim when the input method changes? I know
> this is how the old code works but I specifically changed the new IM
> code so that it did not have to.
I have moved code from activateIm to checkImState because I'd like to solve
the above mentioned problem. The IM switching event and the key-bind for
switching IM (like Cmd-Space) doesn't reach MacVim. So MacVim can't know
the current IM state. MacVim should do polling to get the current IM state.
I think keyDown: method is reasonable to get the current IM state.
(If I can use CFNotificationCenterAddObserver with
kTISNotifySelectedKeyboardInputSourceChanged,
we can get rid of the polling to get the current IM state.)
And I need to send the Activate/DeactivateImMsgID to Vim(MMBackend) when
the input method changes, because, with "noimdisable" option, Vim will save
the current IM state to "iminsert" option value when Vim exits from insert
mode. Vim will use "iminsert" option value to activate/deactivate IM when
Vim enters insert mode. Also you can set "iminert" option by yourself,
for example, you can do ":set iminsert=0" when ESC is pressed by Vim script.
Besides, Vim will use it when user press "Ctrl-^" key-bind that means
switch IM.
"before" meant that MacVim checks the IM state before sending key event to Vim.
"after" meant that MacVim checks the IM state after sending key event to Vim.
The difference between "before" and "after" makes a different behavior of Vim.
"after" behavior:
1. user enters insert mode.
2. user enables IM.
3. user inputs texts using IM.
3.1. MMBackend's current IM state is "enabled".
4. user disables IM.
4.1. MacVim doesn't receive any events at this time.
So MMBackend's current IM state is "enabled".
5. user presses Esc key.
5.1. MacVim's keyDown: method is called.
5.2. MacVim sends the key code ("Esc") to Vim.
5.3. Vim saves MMBackend's current IM state ("enabled") to
"iminsert" option (the value is "2").
5.4. Vim sends "disable IM" message to MacVim.
5.5. MacVim disables IM.
5.6. Vim enters normal mode.
5.7. MacVim checks the current IM state ("disabled")
and save the current IM state to MMBackend.
MMBackend's current IM state is "disabled".
6. user enters insert mode.
6.1. Vim sends "enable IM" message to MacVim because "iminsert" is "2".
6.2. MacVim enables IM.
7. user inputs texts with IM, although user disabled IM.
"before" behavior:
1. user enters insert mode.
2. user enables IM.
3. user inputs texts using IM.
3.1. MMBackend's current IM state is "enabled".
4. user disables IM.
4.1. MacVim doesn't receive any events at this time.
So MacVim's current IM state is "enabled".
5. user presses Esc key.
5.1. MacVim's keyDown: method is called.
5.2. MacVim checks the current IM state ("disabled")
and save the current IM state to MMBackend.
MMBackend's current IM state is "disabled".
5.3. MacVim sends the key code ("Esc") to Vim.
5.4. Vim saves MMBackend's current IM state ("disabled") to
"iminsert" option (the value is "0").
5.5. Vim sends "disable IM" message to MacVim.
5.6. MacVim disables IM.
5.7. Vim enters normal mode.
6. user enters insert mode.
6.1. Vim doesn't send "enable IM" message to MacVim
because "iminsert" is "0".
7. user inputs texts without IM, that user expected.
> With your patch, as soon as I enter insert mode it switches to Swedish
> layout (I'm in Sweden).
It is because the default value of "iminsert" is "2".
I don't know the reason of it. I do ":set iminert=0 imsearch=0" in vimrc.
> If I have several different layouts, e.g. US,
> Swedish and Kotoeri, and go to insert mode and switch to Kotoeri, then
> when I press Esc and go back to insert mode it will go back to Swedish
> again even though it should swtich to Kotoeri (the last layout used in
> insert mode).
Sorry, I don't suppose this behavior.
I have fixed patch to remember IM source properly.
Switch to Kotoeri from ASCII in insert mode,
then press Esc and go back to insert mode, it will go back to Koroeri.
Switch to Swedish from Koroeri in insert mode,
then press Esc and go back to insert mode, it will go back to Swedish.
>> > HACK! interpretKeyEvents: does not call doCommandBySelector:
>> > with Ctrl-6 or Ctrl-^ when IM is active.
>> Ctrl-^ switches IM state in Vim, it works properly on MacVim when IM
>> is not active. So I hacked handling Ctrl-6 and Ctrl-^ when IM is
>> active.
> I don't like this, but I can't think of any way to handle it better.
> Note that your solution will break if 'macmeta' is enabled.
I have fixed it doesn't break 'macmeta' as possible as I can.
sakamoto
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
0001-modify-TIS-handling-for-cooperation-with-iminsert-im.patch
Description: Binary data
