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.
This commit is contained in:
parent
e6c6e0dd59
commit
88205a8d32
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user