diff options
Diffstat (limited to 'qutebrowser/browser/commands.py')
-rw-r--r-- | qutebrowser/browser/commands.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 4f782c3ee..939f02108 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1538,13 +1538,14 @@ class CommandDispatcher: message.error(str(e)) ed.backup() - def _search_cb(self, found, *, tab, old_scroll_pos, options, text, prev): + def _search_cb(self, found, *, tab, old_current_match, options, text, prev): """Callback called from search/search_next/search_prev. Args: found: Whether the text was found. tab: The AbstractTab in which the search was made. - old_scroll_pos: The scroll position (QPoint) before the search. + old_current_match: The previously active match before the search + was performed. options: The options (dict) the search was made with. text: The text searched for. prev: Whether we're searching backwards (i.e. :search-prev) @@ -1556,11 +1557,24 @@ class CommandDispatcher: going_up = options['reverse'] ^ prev if found: - # Check if the scroll position got smaller and show info. - if not going_up and tab.scroller.pos_px().y() < old_scroll_pos.y(): - message.info("Search hit BOTTOM, continuing at TOP") - elif going_up and tab.scroller.pos_px().y() > old_scroll_pos.y(): - message.info("Search hit TOP, continuing at BOTTOM") + if not config.val.search.wrap_messages: + return + + new_current_match = tab.search.current_match + # Check if the match count change is opposite to the search direction + if old_current_match > 0: + if not going_up: + if old_current_match > new_current_match: + message.info("Search hit BOTTOM, continuing at TOP", + replace="search-hit-msg") + elif old_current_match == new_current_match: + message.info("Search hit BOTTOM", replace="search-hit-msg") + elif going_up: + if old_current_match < new_current_match: + message.info("Search hit TOP, continuing at BOTTOM", + replace="search-hit-msg") + elif old_current_match == new_current_match: + message.info("Search hit TOP", replace="search-hit-msg") else: message.warning(f"Text '{text}' not found on page!", replace='find-in-page') @@ -1591,8 +1605,8 @@ class CommandDispatcher: self._tabbed_browser.search_options = dict(options) cb = functools.partial(self._search_cb, tab=tab, - old_scroll_pos=tab.scroller.pos_px(), - options=options, text=text, prev=False) + old_current_match=0, options=options, + text=text, prev=False) options['result_cb'] = cb tab.scroller.before_jump_requested.emit() @@ -1624,7 +1638,7 @@ class CommandDispatcher: return cb = functools.partial(self._search_cb, tab=tab, - old_scroll_pos=tab.scroller.pos_px(), + old_current_match=tab.search.current_match, options=window_options, text=window_text, prev=False) @@ -1658,7 +1672,7 @@ class CommandDispatcher: return cb = functools.partial(self._search_cb, tab=tab, - old_scroll_pos=tab.scroller.pos_px(), + old_current_match=tab.search.current_match, options=window_options, text=window_text, prev=True) |