From 71d55e92135aba9f11db3691028dab5e59b4e529 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 11 May 2018 08:45:43 -0700 Subject: [PATCH] Refocus command prompt after a new tab is opened when in command mode --- qutebrowser/mainwindow/tabbedbrowser.py | 11 ++++++++++- tests/end2end/features/tabs.feature | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 28c754a97..c473f914d 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -22,7 +22,7 @@ import functools import attr -from PyQt5.QtWidgets import QSizePolicy, QWidget +from PyQt5.QtWidgets import QSizePolicy, QWidget, QApplication from PyQt5.QtCore import pyqtSignal, pyqtSlot, QTimer, QUrl from PyQt5.QtGui import QIcon @@ -458,6 +458,8 @@ class TabbedBrowser(QWidget): "related {}, idx {}".format( url, background, related, idx)) + prev_focus = QApplication.focusWidget() + if (config.val.tabs.tabs_are_windows and self.widget.count() > 0 and not ignore_tabs_are_windows): window = mainwindow.MainWindow(private=self.private) @@ -494,6 +496,13 @@ class TabbedBrowser(QWidget): # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-68076 tab.setFocus() + mode = modeman.instance(self._win_id).mode + if mode in [usertypes.KeyMode.command, usertypes.KeyMode.prompt, + usertypes.KeyMode.yesno]: + # If we were in a command prompt, restore old focus + # The above commands need to be run to switch tabs + prev_focus.setFocus() + tab.show() self.new_tab.emit(tab, idx) return tab diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index a19bc7a97..5f5ae5d29 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -1272,3 +1272,19 @@ Feature: Tab management And I run :enter-mode insert And I run :fake-key -g new Then the javascript message "contents: existingnew" should be logged + + Scenario: Focused prompt after opening link in bg + When I open data/hints/link_input.html + When I run :set-cmd-text -s :message-info + And I open data/hello.txt in a new background tab + And I run :fake-key -g hello-world + And I run :command-accept + Then the message "hello-world" should be shown + + Scenario: Focused prompt after opening link in fg + When I open data/hints/link_input.html + When I run :set-cmd-text -s :message-info + And I open data/hello.txt in a new tab + And I run :fake-key -g hello-world + And I run :command-accept + Then the message "hello-world" should be shown