From 5ec94f96fd4d5e4c5dbde9c31b12155a11e79d17 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 26 Jun 2017 21:51:35 +0200 Subject: [PATCH] Allow a trailing % for :zoom --- qutebrowser/browser/commands.py | 9 ++++++++- tests/end2end/features/zoom.feature | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8fead7269..e0b89c693 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -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') diff --git a/tests/end2end/features/zoom.feature b/tests/end2end/features/zoom.feature index 015b85b17..bc36afe0d 100644 --- a/tests/end2end/features/zoom.feature +++ b/tests/end2end/features/zoom.feature @@ -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