From 423192e9c9c39a89e1db5a134025cd1ec7520c34 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sun, 1 Apr 2018 20:46:52 -0400 Subject: [PATCH 1/6] Join text arguments for :search --- qutebrowser/browser/commands.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f2438cebe..201117763 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1778,14 +1778,16 @@ class CommandDispatcher: replace=True) @cmdutils.register(instance='command-dispatcher', scope='window', - maxsplit=0) - def search(self, text="", reverse=False): + maxsplit=0, star_args_optional=True) + def search(self, *text, reverse=False): """Search for a text on the current page. With no text, clear results. Args: text: The text to search for. reverse: Reverse search direction. """ + text = ' '.join(text) + self.set_mark("'") tab = self._current_widget() From 9ad6cef369038fa7cd012ad328dd24ec2b4e6965 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sun, 1 Apr 2018 20:49:09 -0400 Subject: [PATCH 2/6] Add a test for leading arguments --- tests/end2end/data/search.html | 1 + tests/end2end/features/search.feature | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tests/end2end/data/search.html b/tests/end2end/data/search.html index 003751cfd..fa1da96d9 100644 --- a/tests/end2end/data/search.html +++ b/tests/end2end/data/search.html @@ -16,6 +16,7 @@ BAZ
space travel
/slash
+ -r reversed
follow me!

diff --git a/tests/end2end/features/search.feature b/tests/end2end/features/search.feature index 1374b4e10..85b33c682 100644 --- a/tests/end2end/features/search.feature +++ b/tests/end2end/features/search.feature @@ -45,6 +45,12 @@ Feature: Searching on a page 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 -s /-r reversed + And I run :command-accept + And I wait for "search found -r reversed" in the log + Then "-r reversed" should be found + # This doesn't work because this is QtWebKit behavior. @xfail_norun Scenario: Searching text with umlauts From 76dbfa7305b876e15cb9337617afb2e0ec496557 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Thu, 5 Apr 2018 17:20:50 -0400 Subject: [PATCH 3/6] Allow searching for double semicolons Possibly breaks scripts using :search with ;; to split commands. A workaround is to put the :search command at the end. --- qutebrowser/browser/commands.py | 2 +- tests/end2end/data/search.html | 1 + tests/end2end/features/search.feature | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 201117763..9422cb002 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1778,7 +1778,7 @@ class CommandDispatcher: replace=True) @cmdutils.register(instance='command-dispatcher', scope='window', - maxsplit=0, star_args_optional=True) + maxsplit=0, star_args_optional=True, no_cmd_split=True) def search(self, *text, reverse=False): """Search for a text on the current page. With no text, clear results. diff --git a/tests/end2end/data/search.html b/tests/end2end/data/search.html index fa1da96d9..1064a7d01 100644 --- a/tests/end2end/data/search.html +++ b/tests/end2end/data/search.html @@ -17,6 +17,7 @@ space travel
/slash
-r reversed
+ ;; semicolons
follow me!

diff --git a/tests/end2end/features/search.feature b/tests/end2end/features/search.feature index 85b33c682..2ba075868 100644 --- a/tests/end2end/features/search.feature +++ b/tests/end2end/features/search.feature @@ -51,6 +51,11 @@ Feature: Searching on a page 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 :search ;; semi + 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 From 646e92707a3707d87e5d4ac8b5d251c5780c5068 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Mon, 16 Apr 2018 23:15:56 -0400 Subject: [PATCH 4/6] Call search command directly instead of using arguments --- qutebrowser/browser/commands.py | 6 ++--- qutebrowser/mainwindow/statusbar/command.py | 28 +++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 9422cb002..f2438cebe 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1778,16 +1778,14 @@ class CommandDispatcher: replace=True) @cmdutils.register(instance='command-dispatcher', scope='window', - maxsplit=0, star_args_optional=True, no_cmd_split=True) - def search(self, *text, reverse=False): + maxsplit=0) + def search(self, text="", reverse=False): """Search for a text on the current page. With no text, clear results. Args: text: The text to search for. reverse: Reverse search direction. """ - text = ' '.join(text) - self.set_mark("'") tab = self._current_widget() diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 681e20ac5..8829cc9fe 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -69,6 +69,13 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): self.textChanged.connect(self.updateGeometry) self.textChanged.connect(self._incremental_search) + search_fn = cmdutils.cmd_dict['search'].run + self.search_prefixes = { + '/': lambda search: search_fn(self._win_id, ["--", search]), + '?': lambda search: search_fn(self._win_id, ["-r", "--", search]), + } + + def prefix(self): """Get the currently entered command prefix.""" text = self.text() @@ -162,17 +169,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 +265,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:]) From cbb246fd0b30009e7d898c6598fd121fa6eac519 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Mon, 16 Apr 2018 23:27:06 -0400 Subject: [PATCH 5/6] Update tests for new implementation --- qutebrowser/mainwindow/statusbar/command.py | 1 - tests/end2end/features/search.feature | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 8829cc9fe..dc1df34c2 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -75,7 +75,6 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): '?': lambda search: search_fn(self._win_id, ["-r", "--", search]), } - def prefix(self): """Get the currently entered command prefix.""" text = self.text() diff --git a/tests/end2end/features/search.feature b/tests/end2end/features/search.feature index 2ba075868..568831c0d 100644 --- a/tests/end2end/features/search.feature +++ b/tests/end2end/features/search.feature @@ -40,19 +40,23 @@ 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 -s /-r reversed + 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 :search ;; semi + 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 From 1d2dd5bf55ec42f0fec92634a9472432c3342853 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Thu, 19 Apr 2018 21:16:33 -0400 Subject: [PATCH 6/6] Use CommandDispatcher directly for / searches --- qutebrowser/mainwindow/statusbar/command.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index dc1df34c2..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,10 +71,12 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): self.textChanged.connect(self.updateGeometry) self.textChanged.connect(self._incremental_search) - search_fn = cmdutils.cmd_dict['search'].run + dispatcher = objreg.get('command-dispatcher', + scope='window', window=self._win_id) + search_fn = dispatcher.search self.search_prefixes = { - '/': lambda search: search_fn(self._win_id, ["--", search]), - '?': lambda search: search_fn(self._win_id, ["-r", "--", search]), + '/': search_fn, + '?': functools.partial(search_fn, reverse=True) } def prefix(self):