From 58f0a1f8e1e9c5fa521231c966c484076989476e Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Sat, 17 Jul 2010 16:30:42 +0200
Subject: [PATCH] Make it possible to drag a tab page label to another
 position. (Paul B. Mahol)

---
 runtime/doc/tabpage.txt |  2 +-
 runtime/doc/todo.txt    |  5 ++---
 src/normal.c            | 28 +++++++++++++++++++++++++++-
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/runtime/doc/tabpage.txt b/runtime/doc/tabpage.txt
index 4276ade2e7..34b424355e 100644
--- a/runtime/doc/tabpage.txt
+++ b/runtime/doc/tabpage.txt
@@ -46,7 +46,7 @@ close the tab page.
 OPENING A NEW TAB PAGE:
 
 When starting Vim "vim -p filename ..." opens each file argument in a separate
-tab page (up to 'tabpagemax'). |-p|
+tab page (up to 'tabpagemax').  See |-p|
 
 A double click with the mouse in the non-GUI tab pages line opens a new, empty
 tab page.  It is placed left of the position of the click.  The first click
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt
index 284968fbc4..364ea491cc 100644
--- a/runtime/doc/todo.txt
+++ b/runtime/doc/todo.txt
@@ -30,6 +30,8 @@ be worked on, but only if you sponsor Vim development.  See |sponsor|.
 							*known-bugs*
 -------------------- Known bugs and current work -----------------------
 
+GTK: torn-off menu doesn't work.
+
 Cursor positioning wrong with 0x200e character. (John Becket, 2010 May 6)
 
 Test 69 breaks on MS-Windows, both 32 and 64 builds. (George Reilly, 2010 Feb
@@ -1091,9 +1093,6 @@ Before (beta) release 7.3:
 
 Vim 7.3:
 Patches to possibly include:
-- 9   Make it possible to drag a tab page label to another position with the
-    mouse.
-    Patch by Paul B. Mahol, 2008 Aug 29.
 -   Mac: Patch to disable antialias. (LC Mi, 2008 Aug 23)  Tested on 10.5 and
     10.4.
 -   Patch for adding "J" flag to 'cinoptions': placement of jump label.  (Manuel
diff --git a/src/normal.c b/src/normal.c
index 727ecd0590..5d79f35cd5 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -2281,6 +2281,9 @@ do_mouse(oap, c, dir, count, fixindent)
     pos_T	start_visual;
     int		moved;		/* Has cursor moved? */
     int		in_status_line;	/* mouse in status line */
+#ifdef FEAT_WINDOWS
+    static int	in_tab_line = FALSE; /* mouse clicked in tab line */
+#endif
 #ifdef FEAT_VERTSPLIT
     int		in_sep_line;	/* mouse in vertical separator line */
 #endif
@@ -2358,7 +2361,16 @@ do_mouse(oap, c, dir, count, fixindent)
 	if (!got_click)			/* didn't get click, ignore */
 	    return FALSE;
 	if (!is_drag)			/* release, reset got_click */
+	{
 	    got_click = FALSE;
+#ifdef FEAT_WINDOWS
+	    if (in_tab_line)
+	    {
+		in_tab_line = FALSE;
+		return FALSE;
+	    }
+#endif
+	}
     }
 
 #ifndef FEAT_VISUAL
@@ -2512,8 +2524,14 @@ do_mouse(oap, c, dir, count, fixindent)
     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 - 1);
+	    }
 	    return FALSE;
-	got_click = FALSE;	/* ignore mouse-up and drag events */
+	}
 
 	/* click in a tab selects that tab page */
 	if (is_click
@@ -2522,6 +2540,7 @@ do_mouse(oap, c, dir, count, fixindent)
 # endif
 		&& mouse_col < Columns)
 	{
+	    in_tab_line = TRUE;
 	    c1 = TabPageIdxs[mouse_col];
 	    if (c1 >= 0)
 	    {
@@ -2563,6 +2582,13 @@ do_mouse(oap, c, dir, count, fixindent)
 	}
 	return TRUE;
     }
+    else if (is_drag && in_tab_line)
+    {
+	c1 = TabPageIdxs[mouse_col];
+	tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
+	return FALSE;
+    }
+
 #endif
 
     /*
-- 
GitLab