XVimProject / XVim

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

gg doesn't work when there are leading newlines, and startofline option is set #804

Open antmd opened 9 years ago

antmd commented 9 years ago

Hi Guys,

on develop branch, it seems that 'gg' doesn't work when there are leading newlines in a file, and the startofline option is set.

A brief look at the code suggests this patch:

diff --git a/XVim/NSTextView+VimOperation.m b/XVim/NSTextView+VimOperation.m
index 22cdf37..31100fb 100644
--- a/XVim/NSTextView+VimOperation.m
+++ b/XVim/NSTextView+VimOperation.m
@@ -651,7 +651,7 @@ - (void)xvim_move:(XVimMotion*)motion{
                 } else if (XVim.instance.options.startofline) {
                     // only jump to nonblank line for last line or line number
                     if (motion.motion == MOTION_LASTLINE || motion.motion == MOTION_LINENUMBER) {
-                        r.end = [self.textStorage xvim_firstNonblankInLineAtIndex:r.end allowEOL:NO];
+                        r.end = [self.textStorage xvim_firstNonblankInLineAtIndex:r.end allowEOL:YES];
                     }
                 }
                 [self xvim_moveCursor:r.end preserveColumn:YES];

I've made the change in my clone, and it seems to work so far. I just don't know if there are any other implications as I haven't had a chance to follow through the code. Does anyone know if this patch will break anything else? Happy to open a pull request if it's OK.

Best Regards --Anthony

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

ajylee commented 9 years ago

Looks OK. Still, see testing section in Documents/Developers/PullRequest.md.

Also this raises a deeper issue: xvim_firstNonblankInLineAtIndex:allowEOL does not handle blank lines gracefully when allowEOL is NO.

Edit Looks like the related "deeper issue" is not with xvim_firstNonblankInLineAtIndex:allowEOL. It handles blank lines by returning NSNotFound, so I suppose the problem is xvim_moveCursor:NSNotFound preserveColumn: ... goes to the max index.