From 88205a8d322f76d6f30f4f930bbc3c6cc1b72cee Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 30 Nov 2018 14:17:40 +0100 Subject: [PATCH] Add AbstractScroller.before_jump_requested signal This allows us to save the ' mark without needing access to the TabbedBrowser object. This also changes the places the ' mark is saved slightly: - :navigate doesn't save it anymore as there is no reason to do so (loading the new page will render the mark useless anyways). - When clearing a search, the ' mark isn't saved. - :scroll-anchor now saves the ' mark. --- qutebrowser/browser/browsertab.py | 10 +++++++++- qutebrowser/browser/commands.py | 9 +++------ qutebrowser/browser/hints.py | 4 +--- qutebrowser/components/scrollcommands.py | 5 ++--- qutebrowser/mainwindow/tabbedbrowser.py | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 4bffbb796..3bd4c55c3 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -522,9 +522,17 @@ class AbstractCaret(QObject): class AbstractScroller(QObject): - """Attribute of AbstractTab to manage scroll position.""" + """Attribute of AbstractTab to manage scroll position. + + Signals: + perc_changed: The scroll position changed. + before_jump_requested: + Emitted by other code when the user requested a jump. + Used to set the special ' mark so the user can return. + """ perc_changed = pyqtSignal(int, int) + before_jump_requested = pyqtSignal() def __init__(self, tab: 'AbstractTab', parent: QWidget = None): super().__init__(parent) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 07f6156e6..791e45a1a 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -634,9 +634,6 @@ class CommandDispatcher: count: For `increment` and `decrement`, the number to change the URL by. For `up`, the number of levels to go up in the URL. """ - # save the pre-jump position in the special ' mark - self.set_mark("'") - cmdutils.check_exclusive((tab, bg, window), 'tbw') widget = self._current_widget() url = self._current_url() @@ -1712,7 +1709,6 @@ class CommandDispatcher: text: The text to search for. reverse: Reverse search direction. """ - self.set_mark("'") tab = self._current_widget() if not text: @@ -1733,6 +1729,7 @@ class CommandDispatcher: options=options, text=text, prev=False) options['result_cb'] = cb + tab.scroller.before_jump_requested.emit() tab.search.search(text, **options) @cmdutils.register(instance='command-dispatcher', scope='window') @@ -1750,7 +1747,7 @@ class CommandDispatcher: if window_text is None: raise cmdutils.CommandError("No search done yet.") - self.set_mark("'") + tab.scroller.before_jump_requested.emit() if window_text is not None and window_text != tab.search.text: tab.search.clear() @@ -1784,7 +1781,7 @@ class CommandDispatcher: if window_text is None: raise cmdutils.CommandError("No search done yet.") - self.set_mark("'") + tab.scroller.before_jump_requested.emit() if window_text is not None and window_text != tab.search.text: tab.search.clear() diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 31fd9b6a2..bce185298 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -218,9 +218,7 @@ class HintActions: if context.target in [Target.normal, Target.current]: # Set the pre-jump mark ', so we can jump back here after following - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=self._win_id) - tabbed_browser.set_mark("'") + context.tab.scroll.before_jump_requested.emit() try: if context.target == Target.hover: diff --git a/qutebrowser/components/scrollcommands.py b/qutebrowser/components/scrollcommands.py index 13deb9b6b..10b7d7244 100644 --- a/qutebrowser/components/scrollcommands.py +++ b/qutebrowser/components/scrollcommands.py @@ -94,9 +94,6 @@ def scroll_to_perc(tab: tab.Tab, count: int = None, horizontal: Scroll horizontally instead of vertically. count: Percentage to scroll. """ - # save the pre-jump position in the special ' mark - self.set_mark("'") - if perc is None and count is None: perc = 100 elif count is not None: @@ -109,6 +106,7 @@ def scroll_to_perc(tab: tab.Tab, count: int = None, x = None y = perc + tab.scroller.before_jump_requested.emit() tab.scroller.to_perc(x, y) @@ -120,4 +118,5 @@ def scroll_to_anchor(tab: tab.Tab, name): Args: name: The anchor to scroll to. """ + tab.scroller.before_jump_requested.emit() tab.scroller.to_anchor(name) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 9c6602224..9c14df3ae 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -222,6 +222,7 @@ class TabbedBrowser(QWidget): self._filter.create(self.cur_caret_selection_toggled, tab)) # misc tab.scroller.perc_changed.connect(self.on_scroll_pos_changed) + tab.scroller.before_jump_requested.connect(lambda: self.set_mark("'")) tab.url_changed.connect( functools.partial(self.on_url_changed, tab)) tab.title_changed.connect( @@ -891,8 +892,7 @@ class TabbedBrowser(QWidget): # save the pre-jump position in the special ' mark # this has to happen after we read the mark, otherwise jump_mark # "'" would just jump to the current position every time - self.set_mark("'") - + tab.scroller.before_jump_requested.emit() tab.scroller.to_point(point) else: message.error("Mark {} is not set".format(key))