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:
parent
a4569b11ad
commit
a80c61e78a
@ -1269,6 +1269,15 @@ class CommandDispatcher:
|
|||||||
except webelem.IsNullError:
|
except webelem.IsNullError:
|
||||||
raise cmdexc.CommandError("Element vanished while editing!")
|
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',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
maxsplit=0)
|
maxsplit=0)
|
||||||
def search(self, text="", reverse=False):
|
def search(self, text="", reverse=False):
|
||||||
@ -1279,11 +1288,7 @@ class CommandDispatcher:
|
|||||||
reverse: Reverse search direction.
|
reverse: Reverse search direction.
|
||||||
"""
|
"""
|
||||||
view = self._current_widget()
|
view = self._current_widget()
|
||||||
if view.search_text is not None and view.search_text != text:
|
self._clear_search(text)
|
||||||
# We first clear the marked text, then the highlights
|
|
||||||
view.search('', 0)
|
|
||||||
view.search('', QWebPage.HighlightAllOccurrences)
|
|
||||||
|
|
||||||
flags = 0
|
flags = 0
|
||||||
ignore_case = config.get('general', 'ignore-case')
|
ignore_case = config.get('general', 'ignore-case')
|
||||||
if ignore_case == 'smart':
|
if ignore_case == 'smart':
|
||||||
@ -1301,6 +1306,10 @@ class CommandDispatcher:
|
|||||||
view.search(text, flags | QWebPage.HighlightAllOccurrences)
|
view.search(text, flags | QWebPage.HighlightAllOccurrences)
|
||||||
view.search_text = text
|
view.search_text = text
|
||||||
view.search_flags = flags
|
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,
|
@cmdutils.register(instance='command-dispatcher', hide=True,
|
||||||
scope='window', count='count')
|
scope='window', count='count')
|
||||||
@ -1311,7 +1320,14 @@ class CommandDispatcher:
|
|||||||
count: How many elements to ignore.
|
count: How many elements to ignore.
|
||||||
"""
|
"""
|
||||||
view = self._current_widget()
|
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):
|
for _ in range(count):
|
||||||
view.search(view.search_text, view.search_flags)
|
view.search(view.search_text, view.search_flags)
|
||||||
|
|
||||||
@ -1324,8 +1340,13 @@ class CommandDispatcher:
|
|||||||
count: How many elements to ignore.
|
count: How many elements to ignore.
|
||||||
"""
|
"""
|
||||||
view = self._current_widget()
|
view = self._current_widget()
|
||||||
if view.search_text is None:
|
main_window = objreg.get('main-window', scope='window',
|
||||||
return
|
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
|
# 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
|
# QFlags instance rather as a reference. I don't know why it works this
|
||||||
# way, but it does.
|
# way, but it does.
|
||||||
|
@ -109,6 +109,8 @@ class MainWindow(QWidget):
|
|||||||
self._commandrunner = None
|
self._commandrunner = None
|
||||||
self.win_id = next(win_id_gen)
|
self.win_id = next(win_id_gen)
|
||||||
self.registry = objreg.ObjectRegistry()
|
self.registry = objreg.ObjectRegistry()
|
||||||
|
self.search_text = None
|
||||||
|
self.search_flags = 0
|
||||||
objreg.window_registry[self.win_id] = self
|
objreg.window_registry[self.win_id] = self
|
||||||
objreg.register('main-window', self, scope='window',
|
objreg.register('main-window', self, scope='window',
|
||||||
window=self.win_id)
|
window=self.win_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user