Hi Gary!

On Mi, 05 Aug 2015, Gary Johnson wrote:

> The command zt, which scrolls the current line to the top of the
> screen, does not always work in a window that's in diff mode.
> Depending on the line that the cursor is on, it either works
> correctly, scrolls the current line part way up the screen, or has
> no effect at all.
> 
> Here is an example, using terminal vim in a 24-line terminal (xterm)
> window.
> 
>     $ vimdiff -N -u NONE <(seq 30; seq 61 90) <(seq 90)
>     31G
> 
> The cursor is on the line with the text "61" and at the bottom of
> the screen.  Type
> 
>     zt
> 
> The left window now looks like this, with cursor still on the "61"
> line.  This is not the behavior I would expect and seems wrong.
> 
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       --------------------------------------
>       61                                    
>       62                                    
>       63                                    
>       64                                    
>       65                                    
>       66                                    
>     + +--   24 lines: 67--------------------
> 
> Type
> 
>     zt
> 
> again.  There is no change.  Now move the cursor to the line with
> "62" and repeat:
> 
>     j
>     zt
> 
> There is still no change to the window.  Now move the cursor to the
> next line, containing "63" and repeat:
> 
>     j
>     zt
> 
> This time, that line is put at the top of the screen as one would
> expect.  The window now looks like this, as I would expect.
> 
>       63                                    
>       64                                    
>       65                                    
>       66                                    
>     + +--   24 lines: 67--------------------
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
>       ~                                     
> 
> Moving the cursor up a line with k redraws the screen to look as in
> the first illustration above.  This also seems wrong.
> 
> I am using Vim 7.4.808 in an xterm on a system running Fedora 17
> Linux.  FWIW, the behavior is the same in 7.3.444, so this is not
> new.

Here is a patch.

Problem is, that the number of filler lines is added twice to the number 
of physical lines, which seems to be the case since Vim 7.0

A minor open question remains, whether the filler lines should be 
displayed above or not. I have left a comment in the code, whatever 
seems to be right, can be adjusted.

FWIW: I would prefer to not display the filler lines above, so the 
commented line should be uncommented, but the current implementation 
explicitly states, that they should belong to the context and therefore 
shown, so this is what the current patch does.

Best,
Christian
-- 
Nachbar:
  Zeitgenosse, der von Ihren Angelegenheiten mehr weiß als Sie.

-- 
-- 
You received this message from the "vim_dev" 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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/move.c b/src/move.c
--- a/src/move.c
+++ b/src/move.c
@@ -1709,7 +1709,7 @@ scroll_cursor_top(min_scroll, always)
     int		scrolled = 0;
     int		extra = 0;
     int		used;
-    int		i;
+    int		i = 0;
     linenr_T	top;		/* just above displayed lines */
     linenr_T	bot;		/* just below displayed lines */
     linenr_T	old_topline = curwin->w_topline;
@@ -1732,7 +1732,7 @@ scroll_cursor_top(min_scroll, always)
      * - at least 'scrolloff' lines above and below the cursor
      */
     validate_cheight();
-    used = curwin->w_cline_height;
+    used = curwin->w_cline_height; /* includes filler lines above */
     if (curwin->w_cursor.lnum < curwin->w_topline)
 	scrolled = used;
 
@@ -1751,9 +1751,12 @@ scroll_cursor_top(min_scroll, always)
     new_topline = top + 1;
 
 #ifdef FEAT_DIFF
-    /* count filler lines of the cursor window as context */
-    i = diff_check_fill(curwin, curwin->w_cursor.lnum);
-    used += i;
+    /* used already contains the number of filler lines above, don't add it
+     * again.
+     * TODO: if filler lines above new top are to be considered as context for
+     * the current window, leave next statement commented, else hide filler
+     * lines above cursor line, by adding them to extra */
+    /* i = diff_check_fill(curwin, curwin->w_cursor.lnum); */
     extra += i;
 #endif
 

Raspunde prin e-mail lui