Patch 9.0.0911
Problem:    With 'smoothscroll' set mouse click position may be wrong.
Solution:   Adjust computations for w_skipcol. (Yee Cheng Chin, closes #11514)
Files:      src/mouse.c, src/testdir/test_scroll_opt.vim


*** ../vim-9.0.0910/src/mouse.c 2022-11-19 10:47:45.758339628 +0000
--- src/mouse.c 2022-11-19 14:30:50.656793416 +0000
***************
*** 3034,3047 ****
                    row -= win->w_topfill;
                else
                    row -= diff_check_fill(win, lnum);
!               count = plines_win_nofill(win, lnum, TRUE);
            }
            else
  #endif
!               count = plines_win(win, lnum, TRUE);
            if (plines_cache != NULL && cache_idx < Rows)
                plines_cache[cache_idx] = count;
        }
        if (count > row)
            break;      // Position is in this buffer line.
  #ifdef FEAT_FOLDING
--- 3034,3062 ----
                    row -= win->w_topfill;
                else
                    row -= diff_check_fill(win, lnum);
!               count = plines_win_nofill(win, lnum, FALSE);
            }
            else
  #endif
!               count = plines_win(win, lnum, FALSE);
            if (plines_cache != NULL && cache_idx < Rows)
                plines_cache[cache_idx] = count;
        }
+ 
+       if (win->w_skipcol > 0 && lnum == win->w_topline)
+       {
+           // Adjust for 'smoothscroll' clipping the top screen lines.
+           // A similar formula is used in curs_columns().
+           int width1 = win->w_width - win_col_off(win);
+           int skip_lines = 0;
+           if (win->w_skipcol > width1)
+               skip_lines = (win->w_skipcol - width1)
+                                           / (width1 + win_col_off2(win)) + 1;
+           else if (win->w_skipcol > 0)
+               skip_lines = 1;
+           count -= skip_lines;
+       }
+ 
        if (count > row)
            break;      // Position is in this buffer line.
  #ifdef FEAT_FOLDING
***************
*** 3063,3070 ****
        if (col < off)
            col = off;
        col += row * (win->w_width - off);
!       // add skip column (for long wrapping line)
!       col += win->w_skipcol;
      }
  
      if (!win->w_p_wrap)
--- 3078,3087 ----
        if (col < off)
            col = off;
        col += row * (win->w_width - off);
! 
!       // Add skip column for the topline.
!       if (lnum == win->w_topline)
!           col += win->w_skipcol;
      }
  
      if (!win->w_p_wrap)
*** ../vim-9.0.0910/src/testdir/test_scroll_opt.vim     2022-11-19 
12:24:39.758174328 +0000
--- src/testdir/test_scroll_opt.vim     2022-11-19 14:22:39.956675936 +0000
***************
*** 2,7 ****
--- 2,8 ----
  
  source check.vim
  source screendump.vim
+ source mouse.vim
  
  func Test_reset_scroll()
    let scr = &l:scroll
***************
*** 452,456 ****
--- 453,517 ----
    bwipeout!
  endfunc
  
+ " Test that mouse picking is still accurate when we have smooth scrolled lines
+ func Test_smoothscroll_mouse_pos()
+   CheckNotGui
+   CheckUnix
+ 
+   let save_mouse = &mouse
+   let save_term = &term
+   let save_ttymouse = &ttymouse
+   set mouse=a term=xterm ttymouse=xterm2
+ 
+   call NewWindow(10, 20)
+   setl smoothscroll wrap
+   " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
+   call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 
"line 2", "line 3"])
+ 
+   func s:check_mouse_click(row, col, buf_row, buf_col)
+     call MouseLeftClick(a:row, a:col)
+ 
+     call assert_equal(a:col, wincol())
+     call assert_equal(a:row, winline())
+     call assert_equal(a:buf_row, line('.'))
+     call assert_equal(a:buf_col, col('.'))
+   endfunc
+ 
+   " Check that clicking without scroll works first.
+   call s:check_mouse_click(3, 5, 1, 45)
+   call s:check_mouse_click(4, 1, 2, 1)
+   call s:check_mouse_click(4, 6, 2, 6)
+   call s:check_mouse_click(5, 1, 3, 1)
+   call s:check_mouse_click(5, 6, 3, 6)
+ 
+   " Smooth scroll, and checks that this didn't mess up mouse clicking
+   exe "normal \<C-E>"
+   call s:check_mouse_click(2, 5, 1, 45)
+   call s:check_mouse_click(3, 1, 2, 1)
+   call s:check_mouse_click(3, 6, 2, 6)
+   call s:check_mouse_click(4, 1, 3, 1)
+   call s:check_mouse_click(4, 6, 3, 6)
+ 
+   exe "normal \<C-E>"
+   call s:check_mouse_click(1, 5, 1, 45)
+   call s:check_mouse_click(2, 1, 2, 1)
+   call s:check_mouse_click(2, 6, 2, 6)
+   call s:check_mouse_click(3, 1, 3, 1)
+   call s:check_mouse_click(3, 6, 3, 6)
+ 
+   " Make a new first line 11 physical lines tall so it's taller than window
+   " height, to test overflow calculations with really long lines wrapping.
+   normal gg
+   call setline(1, "12345678901234567890"->repeat(11))
+   exe "normal 6\<C-E>"
+   call s:check_mouse_click(5, 1, 1, 201)
+   call s:check_mouse_click(6, 1, 2, 1)
+   call s:check_mouse_click(7, 1, 3, 1)
+ 
+   let &mouse = save_mouse
+   let &term = save_term
+   let &ttymouse = save_ttymouse
+ endfunc
+ 
  
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0910/src/version.c       2022-11-19 13:59:39.511861139 +0000
--- src/version.c       2022-11-19 14:25:50.232725970 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     911,
  /**/

-- 
I AM THANKFUL...
...for a lawn that needs mowing, windows that need cleaning
and gutters that need fixing because it means I have a home.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221119143136.113891C12B2%40moolenaar.net.

Raspunde prin e-mail lui