On 14-Mar-2010 Dominique Pellé <dominique.pe...@gmail.com> wrote:
> 
> So the position of the cursor is wrong. I think
> curwin->w_cursor.lnum is 0 because it's set
> in popupmnu.c:643 to 0:
> 
> 643                     curwin->w_cursor.lnum = 0;
> 
> If I replace this line with...
> 
> 643                     curwin->w_cursor.lnum = 1;
> 
> ... then E38 no longer happens, but I have no idea
> whether this fix is correct!
> 
> $ hg diff popupmnu.c
> diff -r aab202d244b6 src/popupmnu.c
> --- a/src/popupmnu.c  Wed Mar 10 17:16:12 2010 +0100
> +++ b/src/popupmnu.c  Sun Mar 14 10:50:53 2010 +0100
> @@ -640,7 +640,7 @@
> 
>                   curbuf->b_changed = 0;
>                   curbuf->b_p_ma = FALSE;
> -                 curwin->w_cursor.lnum = 0;
> +                 curwin->w_cursor.lnum = 1;
>                   curwin->w_cursor.col = 0;
> 
>                   if (curwin != curwin_save && win_valid(curwin_save))

Your modification fixes more than just this problem. Accidentally, I was
recently investigating a problem with scrolling the preview window when
the pop-up menu is visible. This can be reproduced as follows:
- build C tags for Vim sources,
- open ex_docmd.c in Gvim, go to line 1689,
- set 'cot' to "menu,preview", set 'number',
- insert the following line:
        if (ea.
- without leaving the insert mode invoke omnicompletion by pressing <C-o>,
- move the mouse pointer so that it hovers over the preview window and
  use the mouse scroll wheel to first scroll the window's contents up
  (by rotating the scroll wheel DOWN).

At this point the preview window will have scrolled by 1 line in the
opposite direction than intended and will show line number 0, containing
a copy of line 1. What is more, if you scroll the mouse wheel up, you
will be able to make the window display lines with negative numbers.

Your patch prevents Gvim from behaving this way. My modifications fix
the problem too but they do not fix the problem reported by Dasn.
However, I am still attaching a patch for Bram to consider whether it is
worthwhile to include the changes just for the sake of safety.

The patch also includes a change to fold.c - I removed a redundant
check.

-- 
Cheers,
Lech

-- 
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
diff --git a/src/fold.c b/src/fold.c
index a23a35c..c88e8f7 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1053,15 +1053,14 @@ find_wl_entry(win, lnum)
 {
     int		i;
 
-    if (win->w_lines_valid > 0)
-	for (i = 0; i < win->w_lines_valid; ++i)
-	    if (win->w_lines[i].wl_valid)
-	    {
-		if (lnum < win->w_lines[i].wl_lnum)
-		    return -1;
-		if (lnum <= win->w_lines[i].wl_lastlnum)
-		    return i;
-	    }
+    for (i = 0; i < win->w_lines_valid; ++i)
+	if (win->w_lines[i].wl_valid)
+	{
+	    if (lnum < win->w_lines[i].wl_lnum)
+		return -1;
+	    if (lnum <= win->w_lines[i].wl_lastlnum)
+		return i;
+	}
     return -1;
 }
 
diff --git a/src/move.c b/src/move.c
index b4818ff..544bdb4 100644
--- a/src/move.c
+++ b/src/move.c
@@ -262,6 +262,9 @@ update_topline()
 	}
     }
 
+    if (curwin->w_topline < 1)
+        curwin->w_topline = 1;
+
     /*
      * If the cursor is below the bottom of the window, scroll the window
      * to put the cursor on the window.
@@ -1264,7 +1267,7 @@ scrolldown(line_count, byfold)
 	else
 #endif
 	{
-	    if (curwin->w_topline == 1)
+	    if (curwin->w_topline <= 1)
 		break;
 	    --curwin->w_topline;
 #ifdef FEAT_DIFF

Raspunde prin e-mail lui