patch 9.1.1643: tabpanel: mouse code too complicated

Commit: 
https://github.com/vim/vim/commit/20a159b55771d66878dccaa28b84894a4fc4a852
Author: Hirohito Higashi <h.east....@gmail.com>
Date:   Sun Aug 17 21:09:56 2025 +0200

    patch 9.1.1643: tabpanel: mouse code too complicated
    
    Problem:  tabpanel: mouse code too complicated
    Solution: Refactor code, adjust ifdefs (Hirohito Higashi).
    
    closes: #18023
    
    Signed-off-by: Hirohito Higashi <h.east....@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/mouse.c b/src/mouse.c
index b7696b8db..88d17a545 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -232,9 +232,7 @@ do_mouse(
     int                moved;          // Has cursor moved?
     int                in_status_line; // mouse in status line
     static int in_tab_line = FALSE; // mouse clicked in tab line
-#if defined(FEAT_TABPANEL)
     static int in_tabpanel = FALSE; // mouse clicked in tabpanel
-#endif
     int                in_sep_line;    // mouse in vertical separator line
     int                c1, c2;
 #if defined(FEAT_FOLDING)
@@ -340,9 +338,7 @@ do_mouse(
     {
        got_click = TRUE;
        in_tab_line = FALSE;
-#if defined(FEAT_TABPANEL)
        in_tabpanel = FALSE;
-#endif
     }
     else
     {
@@ -351,16 +347,11 @@ do_mouse(
        if (!is_drag)                   // release, reset got_click
        {
            got_click = FALSE;
-           if (in_tab_line
-#if defined(FEAT_TABPANEL)
-               || in_tabpanel
-#endif
+           if (in_tab_line || in_tabpanel
                    )
            {
                in_tab_line = FALSE;
-#if defined(FEAT_TABPANEL)
                in_tabpanel = FALSE;
-#endif
                return FALSE;
            }
        }
@@ -485,32 +476,61 @@ do_mouse(
 
     start_visual.lnum = 0;
 
+    struct tabpage_label_info {
+       bool is_panel;      // label type. true: tabpanel, false: tab line
+       bool just_in;       // just in tabpage label area
+       bool just_click;    // just click tabpage label area
+       int nr;             // tabpage number
+    } tp_label = { false, false, false, 0 };
+
     // Check for clicking in the tab page panel.
 #if defined(FEAT_TABPANEL)
     if (mouse_row < firstwin->w_winrow + topframe->fr_height
        && (mouse_col < firstwin->w_wincol
                || mouse_col >= firstwin->w_wincol + topframe->fr_width))
+    {
+       tp_label.is_panel = true;
+       tp_label.just_in = true;
+       tp_label.nr = get_tabpagenr_on_tabpanel();
+
+       // click in a tab selects that tab page
+       if (is_click && cmdwin_type == 0)
+           tp_label.just_click = true;
+    }
+    else
+#endif
+    // Check for clicking in the tab page line.
+    if (TabPageIdxs != NULL && mouse_row == 0 && firstwin->w_winrow > 0)
+    {
+       tp_label.just_in = true;
+       tp_label.nr = TabPageIdxs[mouse_col];
+
+       // click in a tab selects that tab page
+       if (is_click && cmdwin_type == 0
+               && mouse_col < firstwin->w_wincol + topframe->fr_width)
+           tp_label.just_click = true;
+    }
+
+    if (tp_label.just_in)
     {
        if (is_drag)
        {
-           if (in_tabpanel)
+           if (in_tabpanel || in_tab_line)
            {
-               c1 = get_tabpagenr_on_tabpanel();
+               c1 = tp_label.nr;
                tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
-                                                               ? c1 - 1 : c1);
+                                                           ? c1 - 1 : c1);
            }
            return FALSE;
        }
 
-       // click in a tab selects that tab page
-       if (is_click
-# ifdef FEAT_CMDWIN
-               && cmdwin_type == 0
-# endif
-               )
+       if (tp_label.just_click)
        {
-           in_tabpanel = TRUE;
-           c1 = get_tabpagenr_on_tabpanel();
+           if (tp_label.is_panel)
+               in_tabpanel = TRUE;
+           else
+               in_tab_line = TRUE;
+           c1 = tp_label.nr;
            if (c1 >= 0)
            {
                if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
@@ -551,82 +571,16 @@ do_mouse(
        }
        return TRUE;
     }
-    else if (is_drag && in_tabpanel)
+    else if (is_drag && (in_tabpanel || in_tab_line))
     {
-       c1 = get_tabpagenr_on_tabpanel();
-       tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
-       return FALSE;
-    }
+#if defined(FEAT_TABPANEL)
+       if (in_tabpanel)
+           c1 = get_tabpagenr_on_tabpanel();
+       else
 #endif
-
-    if (TabPageIdxs != NULL)  // only when initialized
-    {
-       // Check for clicking in the tab page line.
-       if (mouse_row == 0 && firstwin->w_winrow > 0)
-       {
-           if (is_drag)
-           {
-               if (in_tab_line)
-               {
-                   c1 = TabPageIdxs[mouse_col];
-                   tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
-                                                               ? c1 - 1 : c1);
-               }
-               return FALSE;
-           }
-
-           // click in a tab selects that tab page
-           if (is_click && cmdwin_type == 0
-                   && mouse_col < firstwin->w_wincol + topframe->fr_width)
-           {
-               in_tab_line = TRUE;
-               c1 = TabPageIdxs[mouse_col];
-               if (c1 >= 0)
-               {
-                   if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
-                   {
-                       // double click opens new page
-                       end_visual_mode_keep_button();
-                       tabpage_new();
-                       tabpage_move(c1 == 0 ? 9999 : c1 - 1);
-                   }
-                   else
-                   {
-                       // Go to specified tab page, or next one if not clicking
-                       // on a label.
-                       goto_tabpage(c1);
-
-                       // It's like clicking on the status line of a window.
-                       if (curwin != old_curwin)
-                           end_visual_mode_keep_button();
-                   }
-               }
-               else
-               {
-                   tabpage_T   *tp;
-
-                   // Close the current or specified tab page.
-                   if (c1 == -999)
-                       tp = curtab;
-                   else
-                       tp = find_tabpage(-c1);
-                   if (tp == curtab)
-                   {
-                       if (first_tabpage->tp_next != NULL)
-                           tabpage_close(FALSE);
-                   }
-                   else if (tp != NULL)
-                       tabpage_close_other(tp, FALSE);
-               }
-           }
-           return TRUE;
-       }
-       else if (is_drag && in_tab_line)
-       {
            c1 = TabPageIdxs[mouse_col];
-           tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
-           return FALSE;
-       }
+       tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
+       return FALSE;
     }
 
     // When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
diff --git a/src/testdir/test_tabpanel.vim b/src/testdir/test_tabpanel.vim
index 7abf2e9bb..ecc12b59b 100644
--- a/src/testdir/test_tabpanel.vim
+++ b/src/testdir/test_tabpanel.vim
@@ -118,11 +118,33 @@ function Test_tabpanel_mouse()
   call feedkeys("\<LeftMouse>", 'xt')
   call assert_equal(3, tabpagenr())
 
+  " Drag the active tab page
+  tablast
+  call test_setmouse(3, 1)
+  call feedkeys("\<LeftMouse>\<LeftDrag>", 'xt')
+  call test_setmouse(2, 1)
+  call feedkeys("\<LeftDrag>", 'xt')
+  call assert_equal(3, tabpagenr())
+  call feedkeys("\<LeftRelease>", 'xt')
+  tabmove $
+
+  " Drag the inactive tab page
+  tablast
+  call test_setmouse(2, 1)
+  call feedkeys("\<LeftMouse>\<LeftDrag>", 'xt')
+  call test_setmouse(1, 1)
+  call feedkeys("\<LeftDrag>", 'xt')
+  call assert_equal(2, tabpagenr())
+  call feedkeys("\<LeftRelease>", 'xt')
+  tabmove 2
+
   " Confirm that tabpagenr() does not change when dragging outside the tabpanel
+  tablast
   call test_setmouse(3, 30)
-  call feedkeys("\<LeftMouse>", 'xt')
+  call feedkeys("\<LeftMouse>\<LeftDrag>", 'xt')
   call test_setmouse(1, 30)
   call feedkeys("\<LeftDrag>", 'xt')
+  call feedkeys("\<LeftRelease>", 'xt')
   call assert_equal(3, tabpagenr())
 
   call feedkeys("\<LeftMouse>", 'xt')
diff --git a/src/version.c b/src/version.c
index a4d934706..77daa40b8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1643,
 /**/
     1642,
 /**/

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1uniqU-003NGj-L6%40256bit.org.

Raspunde prin e-mail lui