Remove cmdutils.arg_or_count
This commit is contained in:
parent
0345e62348
commit
8a127f2839
@ -717,18 +717,17 @@ class CommandDispatcher:
|
||||
def zoom(self, zoom: int=None, count=None):
|
||||
"""Set the zoom level for the current tab.
|
||||
|
||||
The zoom can be given as argument or as [count]. If neither of both is
|
||||
given, the zoom is set to the default zoom.
|
||||
The zoom can be given as argument or as [count]. If neither is
|
||||
given, the zoom is set to the default zoom. If both are given,
|
||||
use [count].
|
||||
|
||||
Args:
|
||||
zoom: The zoom percentage to set.
|
||||
count: The zoom percentage to set.
|
||||
"""
|
||||
try:
|
||||
default = config.get('ui', 'default-zoom')
|
||||
level = cmdutils.arg_or_count(zoom, count, default=default)
|
||||
except ValueError as e:
|
||||
raise cmdexc.CommandError(e)
|
||||
level = count if count is not None else zoom
|
||||
if level is None:
|
||||
level = config.get('ui', 'default-zoom')
|
||||
tab = self._current_widget()
|
||||
|
||||
try:
|
||||
@ -914,22 +913,18 @@ class CommandDispatcher:
|
||||
if index == 'last':
|
||||
self._tab_focus_last()
|
||||
return
|
||||
if index is None and count is None:
|
||||
index = count if count is not None else index
|
||||
if index is None:
|
||||
self.tab_next()
|
||||
return
|
||||
if index is not None and index < 0:
|
||||
if index < 0:
|
||||
index = self._count() + index + 1
|
||||
try:
|
||||
idx = cmdutils.arg_or_count(index, count, default=1,
|
||||
countzero=self._count())
|
||||
except ValueError as e:
|
||||
raise cmdexc.CommandError(e)
|
||||
cmdutils.check_overflow(idx + 1, 'int')
|
||||
if 1 <= idx <= self._count():
|
||||
self._set_current_index(idx - 1)
|
||||
|
||||
if 1 <= index <= self._count():
|
||||
self._set_current_index(index - 1)
|
||||
else:
|
||||
raise cmdexc.CommandError("There's no tab with index {}!".format(
|
||||
idx))
|
||||
index))
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
@cmdutils.argument('index', choices=['+', '-'])
|
||||
|
@ -48,36 +48,6 @@ def check_overflow(arg, ctype):
|
||||
"representation.".format(ctype))
|
||||
|
||||
|
||||
def arg_or_count(arg, count, default=None, countzero=None):
|
||||
"""Get a value based on an argument and count given to a command.
|
||||
|
||||
If both arg and count are set, ValueError is raised.
|
||||
If only arg/count is set, it is used.
|
||||
If none is set, a default is returned or ValueError is raised.
|
||||
|
||||
Args:
|
||||
arg: The argument given to a command.
|
||||
count: The count given to a command.
|
||||
countzero: Special value if count is 0.
|
||||
|
||||
Return:
|
||||
The value to use.
|
||||
"""
|
||||
if count is not None and arg is not None:
|
||||
raise ValueError("Both count and argument given!")
|
||||
elif arg is not None:
|
||||
return arg
|
||||
elif count is not None:
|
||||
if countzero is not None and count == 0:
|
||||
return countzero
|
||||
else:
|
||||
return count
|
||||
elif default is not None:
|
||||
return default
|
||||
else:
|
||||
raise ValueError("Either count or argument have to be set!")
|
||||
|
||||
|
||||
def check_exclusive(flags, names):
|
||||
"""Check if only one flag is set with exclusive flags.
|
||||
|
||||
|
@ -200,7 +200,7 @@ Feature: Tab management
|
||||
|
||||
Scenario: :tab-focus with very big index
|
||||
When I run :tab-focus 99999999999999
|
||||
Then the error "Numeric argument is too large for internal int representation." should be shown
|
||||
Then the error "There's no tab with index 99999999999999!" should be shown
|
||||
|
||||
Scenario: :tab-focus with count
|
||||
When I open data/numbers/1.txt
|
||||
@ -213,8 +213,14 @@ Feature: Tab management
|
||||
- data/numbers/3.txt
|
||||
|
||||
Scenario: :tab-focus with count and index
|
||||
When I run :tab-focus 2 with count 2
|
||||
Then the error "Both count and argument given!" should be shown
|
||||
When I open data/numbers/1.txt
|
||||
And I open data/numbers/2.txt in a new tab
|
||||
And I open data/numbers/3.txt in a new tab
|
||||
And I run :tab-focus 4 with count 2
|
||||
Then the following tabs should be open:
|
||||
- data/numbers/1.txt
|
||||
- data/numbers/2.txt (active)
|
||||
- data/numbers/3.txt
|
||||
|
||||
Scenario: :tab-focus last
|
||||
When I open data/numbers/1.txt
|
||||
|
@ -71,7 +71,8 @@ Feature: Zooming in and out
|
||||
|
||||
Scenario: Setting zoom with argument and count
|
||||
When I run :zoom 50 with count 60
|
||||
Then the error "Both count and argument given!" should be shown
|
||||
Then the message "Zoom level: 60%" should be shown
|
||||
And the zoom should be 60%
|
||||
|
||||
# Fixed in QtWebEngine branch
|
||||
@xfail
|
||||
|
Loading…
Reference in New Issue
Block a user