diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-06-14 10:46:02 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-06-14 10:46:02 +0200 |
commit | ede1981ccb56068767e74caaff79bcb1f4001668 (patch) | |
tree | 2b4c17a2e3005f98dc1bf3c0b9711e87259cef09 | |
parent | f2ee683a0877c7351d63687f04bd01f9ddbdfd25 (diff) | |
download | qutebrowser-ede1981ccb56068767e74caaff79bcb1f4001668.tar.gz qutebrowser-ede1981ccb56068767e74caaff79bcb1f4001668.zip |
Unify duplicated prev/next search code
-rw-r--r-- | qutebrowser/browser/commands.py | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f534b91b3..e6d2af822 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1600,15 +1600,8 @@ class CommandDispatcher: cb = functools.partial(self._search_cb, text=text) tab.search.search(text, **options, result_cb=cb) - @cmdutils.register(instance='command-dispatcher', scope='window') - @cmdutils.argument('count', value=cmdutils.Value.count) - def search_next(self, count=1): - """Continue the search to the ([count]th) next term. - - Args: - count: How many elements to ignore. - """ - tab = self._current_widget() + def _search_prev_next(self, count, tab, method): + """Continue the search to the prev/next term.""" window_text = self._tabbed_browser.search_text window_options = self._tabbed_browser.search_options @@ -1628,39 +1621,30 @@ class CommandDispatcher: wrap = config.val.search.wrap for _ in range(count - 1): - tab.search.next_result(wrap=wrap) - tab.search.next_result(callback=self._search_navigation_cb, wrap=wrap) + method(wrap=wrap) + method(callback=self._search_navigation_cb, wrap=wrap) @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('count', value=cmdutils.Value.count) - def search_prev(self, count=1): - """Continue the search to the ([count]th) previous term. + def search_next(self, count=1): + """Continue the search to the ([count]th) next term. Args: count: How many elements to ignore. """ tab = self._current_widget() - window_text = self._tabbed_browser.search_text - window_options = self._tabbed_browser.search_options - - if window_text is None: - raise cmdutils.CommandError("No search done yet.") - - tab.scroller.before_jump_requested.emit() - - if window_text is not None and window_text != tab.search.text: - tab.search.clear() - tab.search.search(window_text, **window_options) - count -= 1 + self._search_prev_next(count, tab, tab.search.next_result) - if count == 0: - return - - wrap = config.val.search.wrap + @cmdutils.register(instance='command-dispatcher', scope='window') + @cmdutils.argument('count', value=cmdutils.Value.count) + def search_prev(self, count=1): + """Continue the search to the ([count]th) previous term. - for _ in range(count - 1): - tab.search.prev_result(wrap=wrap) - tab.search.prev_result(callback=self._search_navigation_cb, wrap=wrap) + Args: + count: How many elements to ignore. + """ + tab = self._current_widget() + self._search_prev_next(count, tab, tab.search.prev_result) def _jseval_cb(self, out): """Show the data returned from JS.""" |