diff --git a/docs/changelog.rst b/docs/changelog.rst index e37563e4a..80ba3b10c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -87,6 +87,9 @@ Detailed list of changes - macOS: Add a new service ``Open with kitty`` to open file types that are not 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 :ac:`show_last_command_output` not working when the output is stored diff --git a/docs/layouts.rst b/docs/layouts.rst index d38b48521..ad7564ef0 100644 --- a/docs/layouts.rst +++ b/docs/layouts.rst @@ -138,6 +138,11 @@ define a few extra key bindings in :file:`kitty.conf`:: # the two windows are placed side by side 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 # horizontal or vice versa map F7 layout_action rotate diff --git a/kitty/launch.py b/kitty/launch.py index 466ecc7ef..f4e49a4d6 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -102,16 +102,17 @@ kitty remote control feature with :code:`kitty @launch --copy-env`. --location type=choices 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 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`. 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. -The values of :code:`vsplit` and :code:`hsplit` are only used by the :code:`splits` -layout and control if the new window is placed in a vertical or horizontal split -with the currently active window. The default is to place the window in a -layout dependent manner, typically, after the currently active window. +The values of :code:`vsplit`, :code:`hsplit` and :code:`split` are only used by the +:code:`splits` layout and control if the new window is placed in a vertical, +horizontal or automatic split with the currently active window. The default is +to place the window in a layout dependent manner, typically, after the +currently active window. --allow-remote-control diff --git a/kitty/layout/splits.py b/kitty/layout/splits.py index 597af5d46..b7c7742d2 100644 --- a/kitty/layout/splits.py +++ b/kitty/layout/splits.py @@ -450,13 +450,12 @@ class Splits(Layout): ) -> None: horizontal = self.default_axis_is_horizontal after = True - if location is not None: - if location == 'vsplit': - horizontal = True - elif location == 'hsplit': - horizontal = False - if location in ('before', 'first'): - after = False + if location == 'vsplit': + horizontal = True + elif location == 'hsplit': + horizontal = False + elif location in ('before', 'first'): + after = False aw = all_windows.active_window if aw is not None: ag = all_windows.active_group @@ -464,6 +463,10 @@ class Splits(Layout): group_id = ag.id pair = self.pairs_root.pair_for_window(group_id) 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) pair.split_and_add(group_id, target_group.id, horizontal, after) return