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
This commit is contained in:
Martin Tournoij 2015-09-18 02:18:54 +02:00
parent a4569b11ad
commit a80c61e78a
2 changed files with 31 additions and 8 deletions

View File

@ -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.

View File

@ -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)