diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 672f20d68..f133a1646 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -163,6 +163,8 @@ class AbstractSearch(QObject): super().__init__(parent) self._widget = None self.text = None + # Implementing classes will set this. + self.search_displayed = False def search(self, text, *, ignore_case=False, reverse=False, result_cb=None): @@ -196,10 +198,6 @@ class AbstractSearch(QObject): """ raise NotImplementedError - def searching(self): - """Return True if we are currently searching or not.""" - raise NotImplementedError - class AbstractZoom(QObject): diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 657b6e6da..e460af049 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -127,11 +127,11 @@ class WebEngineSearch(browsertab.AbstractSearch): def __init__(self, parent=None): super().__init__(parent) self._flags = QWebEnginePage.FindFlags(0) - self._searching = False + self.search_displayed = False def _find(self, text, flags, callback, caller): """Call findText on the widget.""" - self._searching = True + self.search_displayed = True def wrapped_callback(found): """Wrap the callback to do debug logging.""" @@ -163,12 +163,9 @@ class WebEngineSearch(browsertab.AbstractSearch): self._find(text, flags, result_cb, 'search') def clear(self): - self._searching = False + self.search_displayed = False self._widget.findText('') - def searching(self): - return self._searching - def prev_result(self, *, result_cb=None): # The int() here makes sure we get a copy of the flags. flags = QWebEnginePage.FindFlags(int(self._flags)) @@ -256,10 +253,10 @@ class WebEngineCaret(browsertab.AbstractCaret): def _follow_selected_cb(self, js_elem, tab=False): """Callback for javascript which clicks the selected element. - Args: - js_elems: The elements serialized from javascript. - tab: Open in a new tab or not. - """ + Args: + js_elems: The elements serialized from javascript. + tab: Open in a new tab or not. + """ if js_elem is None: return assert isinstance(js_elem, dict), js_elem @@ -276,7 +273,7 @@ class WebEngineCaret(browsertab.AbstractCaret): elem.click(click_type) def follow_selected(self, *, tab=False): - if self._tab.search.searching(): + if self._tab.search.search_displayed: # We are currently in search mode. # let's click the link via a fake-click # https://bugreports.qt.io/browse/QTBUG-60673 diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index 44df236a2..0cf83e2a7 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -103,7 +103,7 @@ class WebKitSearch(browsertab.AbstractSearch): def __init__(self, parent=None): super().__init__(parent) self._flags = QWebPage.FindFlags(0) - self._searching = True + self.search_displayed = True def _call_cb(self, callback, found, text, flags, caller): """Call the given callback if it's non-None. @@ -133,14 +133,14 @@ class WebKitSearch(browsertab.AbstractSearch): QTimer.singleShot(0, functools.partial(callback, found)) def clear(self): - self._searching = False + self.search_displayed = False # We first clear the marked text, then the highlights self._widget.findText('') self._widget.findText('', QWebPage.HighlightAllOccurrences) def search(self, text, *, ignore_case=False, reverse=False, result_cb=None): - self._searching = True + self.search_displayed = True flags = QWebPage.FindWrapsAroundDocument if ignore_case == 'smart': if not text.islower(): @@ -158,12 +158,12 @@ class WebKitSearch(browsertab.AbstractSearch): self._call_cb(result_cb, found, text, flags, 'search') def next_result(self, *, result_cb=None): - self._searching = True + self.search_displayed = True found = self._widget.findText(self.text, self._flags) self._call_cb(result_cb, found, self.text, self._flags, 'next_result') def prev_result(self, *, result_cb=None): - self._searching = True + self.search_displayed = True # The int() here makes sure we get a copy of the flags. flags = QWebPage.FindFlags(int(self._flags)) if flags & QWebPage.FindBackward: @@ -173,9 +173,6 @@ class WebKitSearch(browsertab.AbstractSearch): found = self._widget.findText(self.text, flags) self._call_cb(result_cb, found, self.text, flags, 'prev_result') - def searching(self): - return self._searching - class WebKitCaret(browsertab.AbstractCaret): diff --git a/tests/end2end/data/search_select.js b/tests/end2end/data/search_select.js index 8a816c7b7..874e9e9fe 100644 --- a/tests/end2end/data/search_select.js +++ b/tests/end2end/data/search_select.js @@ -1,13 +1,12 @@ /* Select all elements marked with toselect */ - var toSelect = document.getElementsByClassName("toselect"); var s = window.getSelection(); if(s.rangeCount > 0) s.removeAllRanges(); for(var i = 0; i < toSelect.length; i++) { - var range = document.createRange(); - range.selectNode(toSelect[i]); - s.addRange(range); + var range = document.createRange(); + range.selectNode(toSelect[i]); + s.addRange(range); }