After deleting the dedicated window, such as a window with *Completions*
buffer, select the previously selected window, like most of other 'cond'
branches do in this function (bug#52491).
(cond
;; First try to delete dedicated windows that are not side windows.
((and dedicated (not (eq dedicated 'side))
- (window--delete window 'dedicated (eq bury-or-kill 'kill))))
+ (window--delete window 'dedicated (eq bury-or-kill 'kill)))
+ ;; If the previously selected window is still alive, select it.
+ (when (window-live-p (nth 2 quit-restore))
+ (select-window (nth 2 quit-restore))))
((and (not prev-buffer)
(eq (nth 1 quit-restore) 'tab)
(eq (nth 3 quit-restore) buffer))