summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Tournoij <martin@arp242.net>2015-09-18 02:18:54 +0200
committerFlorian Bruhin <git@the-compiler.org>2015-09-30 06:31:23 +0200
commit2e0f8a22f054a4ac1a24e1e2e6cf93fc5e1ab03b (patch)
tree966e81bea7c27018dc08550b87c02b4accc3ffae
parentb8998e7741b90b16043cd69596a0b3b982efa702 (diff)
downloadqutebrowser-2e0f8a22f054a4ac1a24e1e2e6cf93fc5e1ab03b.tar.gz
qutebrowser-2e0f8a22f054a4ac1a24e1e2e6cf93fc5e1ab03b.zip
Use a single search term per-window
Previously, every tab had its own search term. This sets single search term per window. using `/hello`, `gt`, and `n` will search for `hello` in the 2nd tab. This fixes issue #940
-rw-r--r--qutebrowser/browser/commands.py37
-rw-r--r--qutebrowser/mainwindow/mainwindow.py2
2 files changed, 31 insertions, 8 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index 2ac5149f9..be8c0bc26 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -1269,6 +1269,15 @@ class CommandDispatcher:
except webelem.IsNullError:
raise cmdexc.CommandError("Element vanished while editing!")
+ def _clear_search(self, text):
+ """Clear existing search string & highlights for the current view if
+ it's different from text."""
+ view = self._current_widget()
+ if view.search_text is not None and view.search_text != text:
+ # We first clear the marked text, then the highlights
+ view.search('', 0)
+ view.search('', QWebPage.HighlightAllOccurrences)
+
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0)
def search(self, text="", reverse=False):
@@ -1279,11 +1288,7 @@ class CommandDispatcher:
reverse: Reverse search direction.
"""
view = self._current_widget()
- if view.search_text is not None and view.search_text != text:
- # We first clear the marked text, then the highlights
- view.search('', 0)
- view.search('', QWebPage.HighlightAllOccurrences)
-
+ self._clear_search(text)
flags = 0
ignore_case = config.get('general', 'ignore-case')
if ignore_case == 'smart':
@@ -1301,6 +1306,10 @@ class CommandDispatcher:
view.search(text, flags | QWebPage.HighlightAllOccurrences)
view.search_text = text
view.search_flags = flags
+ main_window = objreg.get('main-window', scope='window',
+ window=self._win_id)
+ main_window.search_text = text
+ main_window.search_flags = flags
@cmdutils.register(instance='command-dispatcher', hide=True,
scope='window', count='count')
@@ -1311,7 +1320,14 @@ class CommandDispatcher:
count: How many elements to ignore.
"""
view = self._current_widget()
- if view.search_text is not None:
+ main_window = objreg.get('main-window', scope='window',
+ window=self._win_id)
+
+ self._clear_search(main_window.search_text)
+
+ if main_window.search_text is not None:
+ view.search_text = main_window.search_text
+ view.search_flags = main_window.search_flags
for _ in range(count):
view.search(view.search_text, view.search_flags)
@@ -1324,8 +1340,13 @@ class CommandDispatcher:
count: How many elements to ignore.
"""
view = self._current_widget()
- if view.search_text is None:
- return
+ main_window = objreg.get('main-window', scope='window',
+ window=self._win_id)
+ self._clear_search(main_window.search_text)
+
+ if main_window.search_text is not None:
+ view.search_text = main_window.search_text
+ view.search_flags = main_window.search_flags
# The int() here serves as a QFlags constructor to create a copy of the
# QFlags instance rather as a reference. I don't know why it works this
# way, but it does.
diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py
index 8b13f4e24..460207329 100644
--- a/qutebrowser/mainwindow/mainwindow.py
+++ b/qutebrowser/mainwindow/mainwindow.py
@@ -109,6 +109,8 @@ class MainWindow(QWidget):
self._commandrunner = None
self.win_id = next(win_id_gen)
self.registry = objreg.ObjectRegistry()
+ self.search_text = None
+ self.search_flags = 0
objreg.window_registry[self.win_id] = self
objreg.register('main-window', self, scope='window',
window=self.win_id)