From be6308534f2e3e9a4b94bdf993c58abded2adb5f Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 14 Apr 2016 17:30:43 -0400 Subject: [PATCH] Store both x and y position for marks. Previously only stored/used y. --- qutebrowser/mainwindow/tabbedbrowser.py | 15 +++++++------- tests/integration/features/marks.feature | 26 ++++++++++++------------ tests/integration/features/test_marks.py | 12 ++++------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index ddc3c61ab..56537c167 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -651,15 +651,14 @@ class TabbedBrowser(tabwidget.TabWidget): """ # strip the fragment as it may interfere with scrolling url = self.current_url().adjusted(QUrl.RemoveFragment) - frame = self.currentWidget().page().currentFrame() - y = frame.scrollPosition().y() + point = self.currentWidget().page().currentFrame().scrollPosition() if key.isupper(): - self._global_marks[key] = y, url + self._global_marks[key] = point, url else: if url not in self._local_marks: self._local_marks[url] = {} - self._local_marks[url][key] = y + self._local_marks[url][key] = point def jump_mark(self, key): """Jump to the mark named by `key`. @@ -672,23 +671,23 @@ class TabbedBrowser(tabwidget.TabWidget): frame = self.currentWidget().page().currentFrame() if key.isupper() and key in self._global_marks: - y, url = self._global_marks[key] + point, url = self._global_marks[key] def callback(ok): if ok: self.cur_load_finished.disconnect(callback) - frame.setScrollPosition(QPoint(0, y)) + frame.setScrollPosition(point) self.openurl(url, newtab=False) self.cur_load_finished.connect(callback) elif urlkey in self._local_marks and key in self._local_marks[urlkey]: - y = self._local_marks[urlkey][key] + point = self._local_marks[urlkey][key] # 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("'") - frame.setScrollPosition(QPoint(0, y)) + frame.setScrollPosition(point) else: message.error(self._win_id, "Mark {} is not set".format(key)) diff --git a/tests/integration/features/marks.feature b/tests/integration/features/marks.feature index 5b18a6d05..14ab84bfc 100644 --- a/tests/integration/features/marks.feature +++ b/tests/integration/features/marks.feature @@ -7,43 +7,43 @@ Feature: Setting positional marks ## :set-mark, :jump-mark Scenario: Setting and jumping to a local mark - When I run :scroll-px 0 10 + When I run :scroll-px 5 10 And I run :set-mark 'a' And I run :scroll-px 0 20 And I run :jump-mark 'a' - Then the page should be scrolled to 10 + Then the page should be scrolled to 5 10 Scenario: Jumping back jumping to a particular percentage - When I run :scroll-px 0 20 + When I run :scroll-px 10 20 And I run :scroll-perc 100 And I run :jump-mark "'" - Then the page should be scrolled to 20 + Then the page should be scrolled to 10 20 Scenario: Setting the same local mark on another page - When I run :scroll-px 0 10 + When I run :scroll-px 5 10 And I run :set-mark 'a' And I open data/marks.html And I run :scroll-px 0 20 And I run :set-mark 'a' And I run :jump-mark 'a' - Then the page should be scrolled to 20 + Then the page should be scrolled to 0 20 Scenario: Jumping to a local mark after returning to a page - When I run :scroll-px 0 10 + When I run :scroll-px 5 10 And I run :set-mark 'a' And I open data/numbers/1.txt And I run :set-mark 'a' And I open data/marks.html And I run :jump-mark 'a' - Then the page should be scrolled to 10 + Then the page should be scrolled to 5 10 Scenario: Setting and jumping to a global mark - When I run :scroll-px 0 20 + When I run :scroll-px 5 20 And I run :set-mark 'A' And I open data/numbers/1.txt And I run :jump-mark 'A' Then data/marks.html should be loaded - And the page should be scrolled to 20 + And the page should be scrolled to 5 20 Scenario: Jumping to an unset mark When I run :jump-mark 'b' @@ -58,14 +58,14 @@ Feature: Setting positional marks Scenario: Jumping to a local mark after changing fragments When I open data/marks.html#top And I run :scroll 'top' - And I run :scroll-px 0 10 + And I run :scroll-px 10 10 And I run :set-mark 'a' When I open data/marks.html#bottom And I run :jump-mark 'a' - Then the page should be scrolled to 10 + Then the page should be scrolled to 10 10 Scenario: Jumping back after following a link When I run :hint links normal And I run :follow-hint s And I run :jump-mark "'" - Then the page should be scrolled to 0 + Then the page should be scrolled to 0 0 diff --git a/tests/integration/features/test_marks.py b/tests/integration/features/test_marks.py index fd61d9489..b2777cbe4 100644 --- a/tests/integration/features/test_marks.py +++ b/tests/integration/features/test_marks.py @@ -21,13 +21,9 @@ import pytest_bdd as bdd bdd.scenarios('marks.feature') -def _get_scroll_y(quteproc): +@bdd.then(bdd.parsers.parse("the page should be scrolled to {x} {y}")) +def check_y(quteproc, x, y): data = quteproc.get_session() pos = data['windows'][0]['tabs'][0]['history'][-1]['scroll-pos'] - return pos['y'] - - -@bdd.then(bdd.parsers.parse("the page should be scrolled to " - "{y}")) -def check_y(quteproc, y): - assert int(y) == _get_scroll_y(quteproc) + assert int(x) == pos['x'] + assert int(y) == pos['y']