From 56d567acb6eae72352e39acf4f206f7cb3195900 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 18 Aug 2021 20:44:14 +0300 Subject: [PATCH] Bind [drag-mouse-1] to tab-bar-mouse-move-tab on tab-bar-map * lisp/tab-bar.el (tab-bar-mouse-move-tab): New command. (tab-bar-map): Bind [drag-mouse-1] to tab-bar-mouse-move-tab. (tab-bar-select-tab): Zero or nil arg means the current tab. * src/xdisp.c (handle_tab_bar_click): Remove restriction to allow dragging the tab to another tab. --- etc/NEWS | 3 ++- lisp/tab-bar.el | 17 +++++++++++++++-- src/xdisp.c | 5 +---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index cb500dd697e..fb553e82ff2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -750,7 +750,8 @@ of the next command to be displayed in a new frame. *** The tab bar now supports more mouse commands. Clicking 'mouse-2' closes the tab, 'mouse-3' displays the context menu -with items that operate on the clicked tab. +with items that operate on the clicked tab. Dragging the tab with +'mouse-1' moves it to another position on the tab bar. *** The key prefix 'C-x t t' displays next command buffer in a new tab. It's bound to the command 'other-tab-prefix' that requests the buffer diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 91d22b4b7b2..68de770e060 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -285,6 +285,16 @@ on a console which has no window system but does have a mouse." (popup-menu menu event))) +(defun tab-bar-mouse-move-tab (event) + (interactive "e") + (let* ((caption (car (posn-string (event-start event)))) + (item (and caption (get-text-property 0 'menu-item caption))) + (from (tab--key-to-number (nth 0 item))) + (caption (car (posn-string (event-end event)))) + (item (and caption (get-text-property 0 'menu-item caption))) + (to (tab--key-to-number (nth 0 item)))) + (tab-bar-move-tab-to to from))) + (defun toggle-tab-bar-mode-from-frame (&optional arg) "Toggle tab bar on or off, based on the status of the current frame. Used in the Show/Hide menu, to have the toggle reflect the current frame. @@ -311,6 +321,7 @@ new frame when the global `tab-bar-mode' is enabled, by using (defvar tab-bar-map (let ((map (make-sparse-keymap))) (define-key map [down-mouse-1] 'tab-bar-mouse-select-tab) + (define-key map [drag-mouse-1] 'tab-bar-mouse-move-tab) (define-key map [mouse-1] 'ignore) (define-key map [down-mouse-2] 'tab-bar-mouse-close-tab) (define-key map [mouse-2] 'ignore) @@ -894,11 +905,13 @@ ARG counts from 1. Negative ARG counts tabs from the end of the tab bar." (let ((key (event-basic-type last-command-event))) (setq arg (if (and (characterp key) (>= key ?1) (<= key ?9)) (- key ?0) - 1)))) + 0)))) (let* ((tabs (funcall tab-bar-tabs-function)) (from-index (tab-bar--current-tab-index tabs)) - (to-index (if (< arg 0) (+ (length tabs) (1+ arg)) arg)) + (to-index (cond ((< arg 0) (+ (length tabs) (1+ arg))) + ((zerop arg) (1+ from-index)) + (t arg))) (to-index (1- (max 1 (min to-index (length tabs)))))) (unless (eq from-index to-index) diff --git a/src/xdisp.c b/src/xdisp.c index 1a4efba4b82..4a5ab172cc1 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -13759,10 +13759,7 @@ handle_tab_bar_click (struct frame *f, int x, int y, bool down_p, frame_to_window_pixel_xy (w, &x, &y); ts = get_tab_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx, &close_p); - if (ts == -1 - /* If the button is released on a tab other than the one where - it was pressed, don't generate the tab-bar button click event. */ - || (ts != 0 && !down_p)) + if (ts == -1) return Qnil; /* If item is disabled, do nothing. */ -- 2.39.2