Allow a trailing % for :zoom

This commit is contained in:
Florian Bruhin 2017-06-26 21:51:35 +02:00
parent 92d5f6c41d
commit 5ec94f96fd
2 changed files with 13 additions and 1 deletions

View File

@ -868,7 +868,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('count', count=True)
def zoom(self, zoom: int = None, count=None):
def zoom(self, zoom=None, count=None):
"""Set the zoom level for the current tab.
The zoom can be given as argument or as [count]. If neither is
@ -879,6 +879,13 @@ class CommandDispatcher:
zoom: The zoom percentage to set.
count: The zoom percentage to set.
"""
if zoom is not None:
try:
zoom = int(zoom.rstrip('%'))
except ValueError:
raise cmdexc.CommandError("zoom: Invalid int value {}"
.format(zoom))
level = count if count is not None else zoom
if level is None:
level = config.get('ui', 'default-zoom')

View File

@ -51,6 +51,11 @@ Feature: Zooming in and out
Then the message "Zoom level: 50%" should be shown
And the zoom should be 50%
Scenario: Setting zoom with trailing %
When I run :zoom 50%
Then the message "Zoom level: 50%" should be shown
And the zoom should be 50%
Scenario: Setting zoom with count
When I run :zoom with count 40
Then the message "Zoom level: 40%" should be shown