Thursday, September 6, 2012

Re: Diff 2 files with lines added at top of second file: confusing

On Wed, September 5, 2012 19:29, chroyer@comcast.net wrote:
> Hi,
> I noticed one scenario where vim is not showing me the diff as I expect.
>
> I have 2 files, a.txt and b.txt that for that test (I have seen it on
> "real" files" )
> a.txt has 100 lines, each line with just a number. Looks like this
> 0
> 1
> 2
> [...]
>
> b.txt is same as on a, but I added a few lines at the top, all with just a
> -1. Looks like this
> -1
> -1
> -1
> 0
> 1
> 2
> 3
> [...]
>
> If I run gvim -d b.txt a.txt, things are as I expect: I see the added
> block of -1, few common lines, then the rest is folded.
>
> But if I run gvim -d a.txt b.txt, I don't initially see the block of -1.
> The vertical scrollbar is all the way to the top (I can't scroll up), the
> first 6 lines are shown with no diff, the rest is folded. If I just scroll
> with the mouse while on window of file a, nothing happens. Same if gg on
> a. But if click on the window where b is, the scroll bar is not partly
> down, and I can scroll up (or gg) to the top of b and see the diff.
>
> I guess it make sense: by default the active window is for a, and it is
> showing the top of a; but it forces me to click on b and scroll every time
> to make sure that I am not missing diffs. And I have forgotten a few
> times...
>
> Am I the only one to see that? If not, would it be possible to have vim
> automatically scroll to show the top of the first diff block, regardless
> of which window it is in?
>
> I am using gvim 7.3.646, on Windows XP. I have diffopt=filler. I have
> tried other settings, including horizontal diffing, but none helped for
> that particular issue.
>
> I searched around, but no success, sorry.

I also have noticed this behaviour and found it quite disturbing.

I don't think, every user needs to mess with autocommands to find a
solution that works for him, but rather Vim should make it right. So
here is a patch:

diff --git a/src/diff.c b/src/diff.c
--- a/src/diff.c
+++ b/src/diff.c
@@ -622,6 +622,9 @@
wp->w_topfill = (n < 0 ? 0 : n);
}
}
+
+ /* Make sure, filler lines on top are correctly displayed */
+ check_scrollbind((linenr_T)0, 0L);
}

/*
@@ -1861,10 +1864,6 @@

diff_redraw(TRUE);

- /* recompute the scroll binding with the new option value, may
- * remove or add filler lines */
- check_scrollbind((linenr_T)0, 0L);
-
return OK;
}

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment