Permalink
Browse files

Fix zooming with a too big count

Fixes #1118
Supersedes #1140
  • Loading branch information...
The-Compiler committed Jun 6, 2016
1 parent 8d5fdf2 commit abfd789f9e310daff9f042fe432975ea082cd862
View
@@ -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
-----
@@ -213,7 +213,7 @@ def init_neighborlist(self):
"""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):
@@ -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 @@ def __init__(self, items=None, default=_UNSET, mode=Modes.exception):
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 @@ def _get_new_item(self, offset):
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:
@@ -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
@@ -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 @@ def test_first_raise(self, neighborlist):
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 @@ def test_last_raise(self, neighborlist):
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()."""

0 comments on commit abfd789

Please sign in to comment.