XVimProject / XVim

Xcode plugin for Vim keybindings
MIT License
5.16k stars 595 forks source link

"^^" inserts '^' character #746

Open themightyoarfish opened 9 years ago

themightyoarfish commented 9 years ago

When hitting ^^, the cursor should jump to the start of the line, which it does, but it also inserts a '^' sign there.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

JugglerShu commented 9 years ago

I couldn't reproduce this. Is reproduce step just typing ^^ in normal mode?

iluuu1994 commented 9 years ago

I can confirm, I'm having the same issue.

JugglerShu commented 9 years ago

Give me more detailed information plz. Versions and what is your input source?

iluuu1994 commented 9 years ago

I'm on OS X Yosemite 10.10.3 (14D136), Xcode Version 6.3.2 (6D2105). Not sure how I can find out what XVim version I'm running on, I've just installed it freshly using Alcatraz, so it should be the latest one.

The file I'm editing is a Swift file. No other Xcode plugins are currently installed that could interfere with XVim.

Let me know if I can provide more helpful information.

JugglerShu commented 9 years ago

What is your input source and keyboard?

iluuu1994 commented 9 years ago

I'm using the builtin Swiss/German keyboard of my MacBook Pro (Retina, Mid 2012).

JugglerShu commented 9 years ago

How do you input ^ in german keyboard? And also let me know your "input source" which can be found at right top on the desktop menu bar.

JugglerShu commented 9 years ago

OK I found that. I think you are using "Swiss German" input source. And the ^ is a kind of a special input in German, right? I now understand why this happens. I'll see how I can fix it.

iluuu1994 commented 9 years ago

Nope, we don't really use the ^ character, like, at all :) But yes, I'm using the Swiss German input source, as mentioned above.

JugglerShu commented 9 years ago

Sorry for late reply. I investigated the problem and now I understand whole mechanism why it happens. But unfortunately fixing it is not easy (straightforward). MacVim also seems to have struggled with handling this kind of input.

To remember the problem I describe the detail here but you don't need to read this if you are not interested. Just skip to the end of this message that explains what I'm going to do with this issue.

The problem come from the input source "Swiss German" and marked text. I assume that you type ^^ to enter one ^ character. What happens when you type ^^ is

  1. On the first ^ input, the input source handles it. At this point input source want another input to fix the text(character) to input to the view. So to express this status, the input source shows unfixed text on the view. This is ^ character with yellow background (in my environment). We call this text markedText in Cocoa term.
  2. On the second ^ input, the input source now fixes the actual text input as ^ character. At this point input source tries to put actual ^ character,which is handled by XVim as go to head of line. At this point both marked ^ is still there.
  3. The problem happens next step. Since input source has shown markedText at 1st step, it needs to delete it. In usual context it can delete it by assuming the marked character is one behind the just inserted actual ^ character. However, because XVim has handled ^ as go to head of line and the insertion point has changed and input source can't delete the marked text properly. So the ^ is left in the text.
    1. Another problem occurs next step too. After fixing ^ character, it seems that the input source keep next marked ^ character next to the just fixed ^ character. I think this is just the feature of the input source (language). So after the cursor goes to the head of line it tries to marked text there, too.

Possible solutions

So I have investigated how MacVim handles this behaviour. The solution is really simple. It disables all the marked text. I think you see that you cannot see any yellow background text when you input to the MacVim even in INSERT mode. I also confirmed this behaviour with Japanese input. So this is one possible solution.

I also found that MacVim has --IM-INSERT-- mode. In this mode it seems that it handles marked text well. I haven't seen well this so I don't know how it works but this is another option.

Since the second option should take longer, I'll implement the first one and see if it cause any serious problem when editing.

iluuu1994 commented 9 years ago

You're right, this is exactly what happens. Let me know when you've implemented the fix and I'll give you feedback. Many thanks!

JugglerShu commented 9 years ago

I have committed the fix on develop branch. Give it a try. Remember that you have to set alwaysuseinputsource to make it work properly.