IdeaVIM scrolling to the wrong line

I've noticed a very annoying issue with IdeaVIM. This problem occurs in IntelliJ 6.0.5 and 7 and with every version of IdeaVIM going back to 0.9. The behavior was somehow introduced with a change to IntelliJ possibly around 6.0.1 or 6.0.2 time frame (I'm almost certain that it's not a change with the actual plugin, but perhaps something in the API that it depends on).

Basically, if an editor is not already open for a file and you click on something that jumps to that file and line number, the final position is not always in the correct spot. If the file is already open, the jump always puts you in the correct place.

The behavior appears to be related to determining the offset in the window. If the place that you are jumping to is within the current view when you close the file, the next time you jump to that position it will work correctly. However, if you scroll away from that position, close the file, and then jump back to it (via Find Usages for example), the cursor will be positioned away from the intended spot by about as far as you scrolled away to begin with.

This problem only occurs when I have the IdeaVIM plugin installed (even if it's disabled). I've been playing around with the plugin code and can't see where it might be changing the cursor position on editor creation.

Anyone else noticed this behavior?

0
6 comments
Avatar
Permanently deleted user

Looks like the culprit is in IdeaVIM, MotionGroup.java, line 2038'ish:

...
if (!visibleAreaEvent.getNewRectangle().equals(visibleAreaEvent.getOldRectangle()))
{
MotionGroup.moveCaretToView(editor, null);
}
...

This call does not seem to handle that fact that the editor is already trying to scroll to somewhere in the file. It could also be that it is using virtual instead of logical positions incorrectly. Like I said, this used to all work but something changed with IntelliJ that caused it to break...possibly something related to the auto-scrolling code.

At any rate, I'm testing this plugin with this line commented out. So far, it doesn't seem to break anything else.

Maddy?

0
Avatar
Permanently deleted user

Looks like the only thing that this code does is keep the cursor within the visible window when you are manually scrolling the view. Now when I scroll away from my cursor, the cursor stays wherever it was instead of moving up or down as I scroll.

As it turns out, I didn't care much for that behavior to start with so I'm actually very pleased with just removing the EditorScrollHandler listener entirely.

Looks like the real fix would be to set the ignore flag in the EditorScrollHandler whenever we are creating and displaying a new editor window since the code that moves the caret into the view doesn't work properly in the case where the current logical line isn't already in the visible window.

0

Yes, I have hit this issue as well on the same releases. It is extremely annoying and almost enough to make me stop using IdeaVIM (but not quite!)

IdeaVIM does not seem to be under very active development. Any chance you could send a patched version?

Thanks,
-Bruce

0
Avatar
Permanently deleted user

Sure, my final fix ended up being to skip the registration of the EditorScrollHandler. If you can build the plugin yourself, just comment out the following lines in MotionGroup.java:

editor.getScrollingModel().addVisibleAreaListener(scrollHandler);

and

editor.getScrollingModel().removeVisibleAreaListener(scrollHandler);

If you don't want to take the time to build it, I've attached a version for 6.0.5 and a version for 7.0 (tested with 7.0M1b, but should work for later versions as well). Just replace your IdeaVIM.jar in <IntelliJ Config>\config\plugins\IdeaVIM\lib with the included version (renaming it back to IdeaVIM.jar).

These are both built from the 0.11.5 and 0.11.5a for 6.0 and 7.0 respectively.

-Aaron



Attachment(s):
IdeaVIM_7.jar
IdeaVIM_6.jar
0

Wow that fixed it, what a relief! Thanks a lot for the patch!

-Bruce

0
Avatar
Permanently deleted user

You are my hero! Thank you! I used your IdeaVIM_7.jar and the problem went away. I have been having this issue for like the last year or so and it was super annoying.

A few months ago I figured it had to be something with my setup or everyone would be complaining about it...I know at one point I suspected IdeaVIM and uninstalled it to test. I could have swore it still occured...hmm. Maybe I just disabled it rather than uninstalling it. Can't remember now.

Anyway, thanks!

0

Please sign in to leave a comment.