diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 898c94dd8..e817f92fe 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -57,6 +57,8 @@ Changed - Rapid hints can now also be used for the `normal` hint target, which can be useful with javascript click handlers or checkboxes which don't actually open a new page. +- `:zoom-in` or `:zoom-out` (`+`/`-`) with a too large count now zooms to the + smallest/largest zoom instead of doing nothing. Fixed ----- diff --git a/qutebrowser/browser/webview.py b/qutebrowser/browser/webview.py index 7078d142a..cc41ad115 100644 --- a/qutebrowser/browser/webview.py +++ b/qutebrowser/browser/webview.py @@ -213,7 +213,7 @@ class WebView(QWebView): """Initialize the _zoom neighborlist.""" levels = config.get('ui', 'zoom-levels') self._zoom = usertypes.NeighborList( - levels, mode=usertypes.NeighborList.Modes.block) + levels, mode=usertypes.NeighborList.Modes.edge) self._zoom.fuzzyval = config.get('ui', 'default-zoom') def _mousepress_backforward(self, e): diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 3d7c2bf10..8fcecde67 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -65,7 +65,7 @@ class NeighborList(collections.abc.Sequence): _mode: The current mode. """ - Modes = enum('Modes', ['block', 'exception']) + Modes = enum('Modes', ['edge', 'exception']) def __init__(self, items=None, default=_UNSET, mode=Modes.exception): """Constructor. @@ -74,7 +74,7 @@ class NeighborList(collections.abc.Sequence): items: The list of items to iterate in. _default: The initially selected value. _mode: Behavior when the first/last item is reached. - Modes.block: Stay on the selected item + Modes.edge: Go to the first/last item Modes.exception: Raise an IndexError. """ if not isinstance(mode, self.Modes): @@ -140,8 +140,13 @@ class NeighborList(collections.abc.Sequence): else: raise IndexError except IndexError: - if self._mode == self.Modes.block: - new = self.curitem() + if self._mode == self.Modes.edge: + if offset == 0: + new = self.curitem() + elif offset > 0: + new = self.lastitem() + else: + new = self.firstitem() elif self._mode == self.Modes.exception: # pragma: no branch raise else: diff --git a/tests/end2end/features/zoom.feature b/tests/end2end/features/zoom.feature index 4b0b1800b..0dddf2ec3 100644 --- a/tests/end2end/features/zoom.feature +++ b/tests/end2end/features/zoom.feature @@ -23,8 +23,21 @@ Feature: Zooming in and out # https://github.com/The-Compiler/qutebrowser/issues/1118 Scenario: Zooming in with very big count When I run :zoom-in with count 99999999999 - Then the message "Zoom level: 100%" should be shown - And the zoom should be 100% + Then the message "Zoom level: 120%" should be shown + And the zoom should be 120% + + # https://github.com/The-Compiler/qutebrowser/issues/1118 + Scenario: Zooming out with very big count + When I run :zoom-out with count 99999999999 + Then the message "Zoom level: 50%" should be shown + And the zoom should be 50% + + # https://github.com/The-Compiler/qutebrowser/issues/1118 + Scenario: Zooming in with very big count and snapping in + When I run :zoom-in with count 99999999999 + And I run :zoom-out + Then the message "Zoom level: 110%" should be shown + And the zoom should be 110% Scenario: Zooming out with count When I run :zoom-out with count 2 diff --git a/tests/unit/utils/usertypes/test_neighborlist.py b/tests/unit/utils/usertypes/test_neighborlist.py index c207498d9..86c896d5c 100644 --- a/tests/unit/utils/usertypes/test_neighborlist.py +++ b/tests/unit/utils/usertypes/test_neighborlist.py @@ -172,9 +172,9 @@ class TestSingleItem: def neighborlist(self): return usertypes.NeighborList([1], default=1) - def test_first_block(self, neighborlist): - """Test out of bounds previtem() with mode=block.""" - neighborlist._mode = usertypes.NeighborList.Modes.block + def test_first_edge(self, neighborlist): + """Test out of bounds previtem() with mode=edge.""" + neighborlist._mode = usertypes.NeighborList.Modes.edge neighborlist.firstitem() assert neighborlist._idx == 0 assert neighborlist.previtem() == 1 @@ -189,9 +189,9 @@ class TestSingleItem: neighborlist.previtem() assert neighborlist._idx == 0 - def test_last_block(self, neighborlist): - """Test out of bounds nextitem() with mode=block.""" - neighborlist._mode = usertypes.NeighborList.Modes.block + def test_last_edge(self, neighborlist): + """Test out of bounds nextitem() with mode=edge.""" + neighborlist._mode = usertypes.NeighborList.Modes.edge neighborlist.lastitem() assert neighborlist._idx == 0 assert neighborlist.nextitem() == 1 @@ -207,15 +207,15 @@ class TestSingleItem: assert neighborlist._idx == 0 -class TestBlockMode: +class TestEdgeMode: - """Tests with mode=block.""" + """Tests with mode=edge.""" @pytest.fixture def neighborlist(self): return usertypes.NeighborList( [1, 2, 3, 4, 5], default=3, - mode=usertypes.NeighborList.Modes.block) + mode=usertypes.NeighborList.Modes.edge) def test_first(self, neighborlist): """Test out of bounds previtem()."""