diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 87ca80ce00a..f0668374773 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1253,6 +1260,14 @@ tab-bar--tabs-recent tabs)))) +(defvar tab-bar-minibuffer-restore-tab nil) + +(defun tab-bar-minibuffer-restore-windows () + (when (and read-minibuffer-restore-windows + tab-bar-minibuffer-restore-tab) + (tab-bar-select-tab tab-bar-minibuffer-restore-tab) + (setq tab-bar-minibuffer-restore-tab nil))) + (defun tab-bar-select-tab (&optional tab-number) "Switch to the tab by its absolute position TAB-NUMBER in the tab bar. When this command is bound to a numeric key (with a key prefix or modifier key @@ -1278,6 +1293,11 @@ tab-bar-select-tab (to-index (1- (max 1 (min to-number (length tabs))))) (minibuffer-was-active (minibuffer-window-active-p (selected-window)))) + (when (and read-minibuffer-restore-windows minibuffer-was-active + (not tab-bar-minibuffer-restore-tab)) + (setq tab-bar-minibuffer-restore-tab (1+ from-index)) + (add-hook 'minibuffer-exit-hook 'tab-bar-minibuffer-restore-windows)) + (unless (eq from-index to-index) (let* ((from-tab (tab-bar--tab)) (to-tab (nth to-index tabs))