Allow specifying an optional integer argument for next_layout. Fixes #6121

This commit is contained in:
Kovid Goyal 2023-03-20 19:49:37 +05:30
parent 1bed92bed1
commit f61ddd62d1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 4 deletions

View File

@ -280,7 +280,7 @@ def remote_control(func: str, rest: str) -> FuncArgsType:
return func, args return func, args
@func_with_args('nth_os_window', 'nth_window', 'scroll_to_prompt', 'visual_window_select_action_trigger') @func_with_args('nth_os_window', 'nth_window', 'scroll_to_prompt', 'visual_window_select_action_trigger', 'next_layout')
def single_integer_arg(func: str, rest: str) -> FuncArgsType: def single_integer_arg(func: str, rest: str) -> FuncArgsType:
try: try:
num = int(rest) num = int(rest)

View File

@ -300,8 +300,8 @@ class Tab: # {{{
def create_layout_object(self, name: str) -> Layout: def create_layout_object(self, name: str) -> Layout:
return create_layout_object_for(name, self.os_window_id, self.id) return create_layout_object_for(name, self.os_window_id, self.id)
@ac('lay', 'Go to the next enabled layout') @ac('lay', 'Go to the next enabled layout. Can optionally supply an integer to jump by the specified number.')
def next_layout(self) -> None: def next_layout(self, delta: int = 1) -> None:
if len(self.enabled_layouts) > 1: if len(self.enabled_layouts) > 1:
for i, layout_name in enumerate(self.enabled_layouts): for i, layout_name in enumerate(self.enabled_layouts):
if layout_name == self.current_layout.full_name: if layout_name == self.current_layout.full_name:
@ -309,7 +309,10 @@ class Tab: # {{{
break break
else: else:
idx = -1 idx = -1
nl = self.enabled_layouts[(idx + 1) % len(self.enabled_layouts)] if abs(delta) >= len(self.enabled_layouts):
mult = -1 if delta < 0 else 1
delta = mult * (abs(delta) % len(self.enabled_layouts))
nl = self.enabled_layouts[(idx + delta + len(self.enabled_layouts)) % len(self.enabled_layouts)]
self._set_current_layout(nl) self._set_current_layout(nl)
self.relayout() self.relayout()