diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 681e20ac5..61b9fb43a 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -19,6 +19,8 @@ """The commandline in the statusbar.""" +import functools + from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QSize from PyQt5.QtWidgets import QSizePolicy @@ -69,6 +71,14 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): self.textChanged.connect(self.updateGeometry) self.textChanged.connect(self._incremental_search) + dispatcher = objreg.get('command-dispatcher', + scope='window', window=self._win_id) + search_fn = dispatcher.search + self.search_prefixes = { + '/': search_fn, + '?': functools.partial(search_fn, reverse=True) + } + def prefix(self): """Get the currently entered command prefix.""" text = self.text() @@ -162,17 +172,17 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): Args: rapid: Run the command without closing or clearing the command bar. """ - prefixes = { - ':': '', - '/': 'search -- ', - '?': 'search -r -- ', - } text = self.text() self.history.append(text) if not rapid: modeman.leave(self._win_id, usertypes.KeyMode.command, 'cmd accept') - self.got_cmd[str].emit(prefixes[text[0]] + text[1:]) + + prefix = text[0] + if prefix in self.search_prefixes: + self.search_prefixes[prefix](text[1:]) + else: + self.got_cmd[str].emit(text[1:]) @cmdutils.register(instance='status-command', scope='window') def edit_command(self, run=False): @@ -258,10 +268,5 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): if not config.val.search.incremental: return - search_prefixes = { - '/': 'search -- ', - '?': 'search -r -- ', - } - - if self.prefix() in ['/', '?']: - self.got_cmd[str].emit(search_prefixes[text[0]] + text[1:]) + if self.prefix() in self.search_prefixes: + self.search_prefixes[self.prefix()](text[1:]) diff --git a/tests/end2end/data/search.html b/tests/end2end/data/search.html index 003751cfd..1064a7d01 100644 --- a/tests/end2end/data/search.html +++ b/tests/end2end/data/search.html @@ -16,6 +16,8 @@ BAZ
space travel
/slash
+ -r reversed
+ ;; semicolons
follow me!

diff --git a/tests/end2end/features/search.feature b/tests/end2end/features/search.feature index 1374b4e10..568831c0d 100644 --- a/tests/end2end/features/search.feature +++ b/tests/end2end/features/search.feature @@ -40,11 +40,26 @@ Feature: Searching on a page Then "space " should be found Scenario: Searching with / and slash in search term (issue 507) - When I run :set-cmd-text -s //slash + When I run :set-cmd-text //slash And I run :command-accept And I wait for "search found /slash" in the log Then "/slash" should be found + Scenario: Searching with arguments at start of search term + When I run :set-cmd-text /-r reversed + And I run :command-accept + And I wait for "search found -r reversed" in the log + Then "-r reversed" should be found + + Scenario: Searching with semicolons in search term + When I run :set-cmd-text /; + And I run :fake-key -g ; + And I run :fake-key -g + And I run :fake-key -g semi + And I run :command-accept + And I wait for "search found ;; semi" in the log + Then ";; semi" should be found + # This doesn't work because this is QtWebKit behavior. @xfail_norun Scenario: Searching text with umlauts