Splits layout: A new value for :option:launch --location to auto-select the split axis when splitting existing windows.

This commit is contained in:
Kovid Goyal 2022-02-22 22:36:50 +05:30
parent 7a2a849a97
commit 31a5965b01
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 24 additions and 12 deletions

View File

@ -87,6 +87,9 @@ Detailed list of changes
- macOS: Add a new service ``Open with kitty`` to open file types that are not - macOS: Add a new service ``Open with kitty`` to open file types that are not
recognized by the system (:pull:`4641`) recognized by the system (:pull:`4641`)
- Splits layout: A new value for :option:`launch --location` to auto-select the split axis when splitting existing windows.
Wide windows are split side-by-side and tall windows are split one-above-the-other
- Fix a regression in the previous release that broke :opt:`active_tab_foreground` (:iss:`4620`) - Fix a regression in the previous release that broke :opt:`active_tab_foreground` (:iss:`4620`)
- Fix :ac:`show_last_command_output` not working when the output is stored - Fix :ac:`show_last_command_output` not working when the output is stored

View File

@ -138,6 +138,11 @@ define a few extra key bindings in :file:`kitty.conf`::
# the two windows are placed side by side # the two windows are placed side by side
map F6 launch --location=vsplit map F6 launch --location=vsplit
# Create a new window splitting the space used by the existing one so that
# the two windows are placed side by side if the existing window is wide or
# one above the other if the existing window is tall.
map F4 launch --location=split
# Rotate the current split, chaging its split axis from vertical to # Rotate the current split, chaging its split axis from vertical to
# horizontal or vice versa # horizontal or vice versa
map F7 layout_action rotate map F7 layout_action rotate

View File

@ -102,16 +102,17 @@ kitty remote control feature with :code:`kitty @launch --copy-env`.
--location --location
type=choices type=choices
default=default default=default
choices=first,after,before,neighbor,last,vsplit,hsplit,default choices=first,after,before,neighbor,last,vsplit,hsplit,split,default
Where to place the newly created window when it is added to a tab which Where to place the newly created window when it is added to a tab which
already has existing windows in it. :code:`after` and :code:`before` place the new already has existing windows in it. :code:`after` and :code:`before` place the new
window before or after the active window. :code:`neighbor` is a synonym for :code:`after`. window before or after the active window. :code:`neighbor` is a synonym for :code:`after`.
Also applies to creating a new tab, where the value of :code:`after` Also applies to creating a new tab, where the value of :code:`after`
will cause the new tab to be placed next to the current tab instead of at the end. will cause the new tab to be placed next to the current tab instead of at the end.
The values of :code:`vsplit` and :code:`hsplit` are only used by the :code:`splits` The values of :code:`vsplit`, :code:`hsplit` and :code:`split` are only used by the
layout and control if the new window is placed in a vertical or horizontal split :code:`splits` layout and control if the new window is placed in a vertical,
with the currently active window. The default is to place the window in a horizontal or automatic split with the currently active window. The default is
layout dependent manner, typically, after the currently active window. to place the window in a layout dependent manner, typically, after the
currently active window.
--allow-remote-control --allow-remote-control

View File

@ -450,13 +450,12 @@ class Splits(Layout):
) -> None: ) -> None:
horizontal = self.default_axis_is_horizontal horizontal = self.default_axis_is_horizontal
after = True after = True
if location is not None: if location == 'vsplit':
if location == 'vsplit': horizontal = True
horizontal = True elif location == 'hsplit':
elif location == 'hsplit': horizontal = False
horizontal = False elif location in ('before', 'first'):
if location in ('before', 'first'): after = False
after = False
aw = all_windows.active_window aw = all_windows.active_window
if aw is not None: if aw is not None:
ag = all_windows.active_group ag = all_windows.active_group
@ -464,6 +463,10 @@ class Splits(Layout):
group_id = ag.id group_id = ag.id
pair = self.pairs_root.pair_for_window(group_id) pair = self.pairs_root.pair_for_window(group_id)
if pair is not None: if pair is not None:
if location == 'split':
wwidth = aw.geometry.right - aw.geometry.left
wheight = aw.geometry.bottom - aw.geometry.top
horizontal = wwidth >= wheight
target_group = all_windows.add_window(window, next_to=aw, before=not after) target_group = all_windows.add_window(window, next_to=aw, before=not after)
pair.split_and_add(group_id, target_group.id, horizontal, after) pair.split_and_add(group_id, target_group.id, horizontal, after)
return return