Merge remote-tracking branch 'origin/pr/3906'
This commit is contained in:
commit
cec63ea449
@ -22,7 +22,7 @@
|
||||
from PyQt5.QtCore import QObject, QEvent, Qt, QTimer
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import message, log, usertypes, qtutils
|
||||
from qutebrowser.utils import message, log, usertypes, qtutils, objreg
|
||||
from qutebrowser.keyinput import modeman
|
||||
|
||||
|
||||
@ -40,11 +40,12 @@ class ChildEventFilter(QObject):
|
||||
_widget: The widget expected to send out childEvents.
|
||||
"""
|
||||
|
||||
def __init__(self, eventfilter, widget, parent=None):
|
||||
def __init__(self, eventfilter, widget, win_id, parent=None):
|
||||
super().__init__(parent)
|
||||
self._filter = eventfilter
|
||||
assert widget is not None
|
||||
self._widget = widget
|
||||
self._win_id = win_id
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
"""Act on ChildAdded events."""
|
||||
@ -57,7 +58,22 @@ class ChildEventFilter(QObject):
|
||||
|
||||
if qtutils.version_check('5.11', compiled=False, exact=True):
|
||||
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-68076
|
||||
pass_modes = [usertypes.KeyMode.command,
|
||||
usertypes.KeyMode.prompt,
|
||||
usertypes.KeyMode.yesno]
|
||||
if modeman.instance(self._win_id).mode not in pass_modes:
|
||||
tabbed_browser = objreg.get('tabbed-browser',
|
||||
scope='window',
|
||||
window=self._win_id)
|
||||
current_index = tabbed_browser.widget.currentIndex()
|
||||
try:
|
||||
widget_index = tabbed_browser.widget.indexOf(
|
||||
self._widget.parent())
|
||||
except RuntimeError:
|
||||
widget_index = -1
|
||||
if current_index == widget_index:
|
||||
QTimer.singleShot(0, self._widget.setFocus)
|
||||
|
||||
elif event.type() == QEvent.ChildRemoved:
|
||||
child = event.child()
|
||||
log.mouse.debug("{}: removed child {}".format(obj, child))
|
||||
|
@ -959,7 +959,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
fp.installEventFilter(self._mouse_event_filter)
|
||||
self._child_event_filter = mouse.ChildEventFilter(
|
||||
eventfilter=self._mouse_event_filter, widget=self._widget,
|
||||
parent=self)
|
||||
win_id=self.win_id, parent=self)
|
||||
self._widget.installEventFilter(self._child_event_filter)
|
||||
|
||||
@pyqtSlot()
|
||||
|
@ -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
|
||||
|
||||
@ -462,6 +462,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)
|
||||
@ -491,12 +493,21 @@ class TabbedBrowser(QWidget):
|
||||
tab.resize(self.widget.currentWidget().size())
|
||||
self.widget.tab_index_changed.emit(self.widget.currentIndex(),
|
||||
self.widget.count())
|
||||
# Refocus webview in case we lost it by spawning a bg tab
|
||||
self.widget.currentWidget().setFocus()
|
||||
else:
|
||||
self.widget.setCurrentWidget(tab)
|
||||
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-68076
|
||||
# Still seems to be needed with Qt 5.11.1
|
||||
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
|
||||
|
25
tests/end2end/data/hints/link_input.html
Normal file
25
tests/end2end/data/hints/link_input.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Simple link and input</title>
|
||||
<script type="text/javascript">
|
||||
function setup_event_listener() {
|
||||
var elem = document.getElementById('qute-input-existing');
|
||||
console.log(elem);
|
||||
elem.addEventListener('input', function() {
|
||||
console.log("contents: " + elem.value);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="setup_event_listener()">
|
||||
<a href="/data/hello.txt" id="link">Follow me!</a>
|
||||
<form><input id="qute-input"></input></form>
|
||||
With padding:
|
||||
<form><input type="text" style="padding-left: 20px;"></input></form>
|
||||
With existing text (logs to JS)::
|
||||
<form><input id="qute-input-existing" value="existing"></input></form>
|
||||
</body>
|
||||
</html>
|
@ -1250,3 +1250,41 @@ Feature: Tab management
|
||||
Then the following tabs should be open:
|
||||
- data/numbers/1.txt
|
||||
- data/numbers/2.txt (pinned) (active)
|
||||
|
||||
|
||||
Scenario: Focused webview after clicking link in bg
|
||||
When I open data/hints/link_input.html
|
||||
And I run :click-element id qute-input-existing
|
||||
And I wait for "Entering mode KeyMode.insert *" in the log
|
||||
And I run :leave-mode
|
||||
And I hint with args "all tab-bg" and follow a
|
||||
And I wait until data/hello.txt is loaded
|
||||
And I run :enter-mode insert
|
||||
And I run :fake-key -g new
|
||||
Then the javascript message "contents: existingnew" should be logged
|
||||
|
||||
Scenario: Focused webview after opening link in bg
|
||||
When I open data/hints/link_input.html
|
||||
And I run :click-element id qute-input-existing
|
||||
And I wait for "Entering mode KeyMode.insert *" in the log
|
||||
And I run :leave-mode
|
||||
And I open data/hello.txt in a new background tab
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user