Action to convert between vertical and horizontal splits

This commit is contained in:
Kovid Goyal 2020-01-30 14:34:40 +05:30
parent 36fda90814
commit c31a39a052
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 41 additions and 0 deletions

View File

@ -241,6 +241,14 @@ def disable_ligatures_in(func, rest):
return func, [where, strategy]
@func_with_args('layout_action')
def layout_action(func, rest):
parts = rest.split(maxsplit=1)
if not parts:
raise ValueError('layout_action must have at least one argument')
return func, [parts[0], tuple(parts[1:])]
def parse_marker_spec(ftype, parts):
flags = re.UNICODE
if ftype in ('text', 'itext', 'regex', 'iregex'):

View File

@ -457,6 +457,9 @@ class Layout: # {{{
yield all_borders
else:
yield no_borders
def layout_action(self, action_name, args, all_windows, active_window_idx):
pass
# }}}
@ -1363,6 +1366,27 @@ class Splits(Layout):
else:
p2.two = w1
def layout_action(self, action_name, args, all_windows, active_window_idx):
if action_name == 'rotate':
args = args or ('90',)
try:
amt = int(args[0])
except Exception:
amt = 90
if amt not in (90, 180, 270):
amt = 90
rotate = amt in (90, 270)
swap = amt in (180, 270)
w = all_windows[active_window_idx]
wid = w.overlay_for or w.id
pair = self.pairs_root.pair_for_window(wid)
if pair is not None and not pair.is_redundant:
if rotate:
pair.horizontal = not pair.horizontal
if swap:
pair.one, pair.two = pair.two, pair.one
return True
# }}}

View File

@ -236,6 +236,15 @@ class Tab: # {{{
if self.current_layout.remove_all_biases():
self.relayout()
def layout_action(self, action_name, args):
ret = self.current_layout.layout_action(action_name, args, self.windows, self.active_window_idx)
if ret is None:
ring_bell()
return
if isinstance(ret, int) and not isinstance(ret, bool):
self.active_window_idx = ret
self.relayout()
def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None, env=None, allow_remote_control=False):
if cmd is None:
if use_shell: