From 20185fc317db5d85f0c5b3d88a22bf3c493102df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 15:04:46 +0000 Subject: [PATCH 1/2] Fix display corruption when maximizing horizontal split with window_padding_width >= 4 (issue #9946) Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/3b0c9eab-24ba-4934-a941-be477477cee4 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- kitty/layout/base.py | 6 +++--- kitty_tests/layout.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/kitty/layout/base.py b/kitty/layout/base.py index 6deb610d2..cb957a1f0 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -117,14 +117,14 @@ def layout_dimension( bias: None | Sequence[float] | dict[int, float] = None ) -> LayoutDimension: number_of_windows = len(decoration_pairs) - number_of_cells = length // cell_length + number_of_cells = max(0, length // cell_length) dec_vals: Iterable[int] = map(sum, decoration_pairs) space_needed_for_decorations = sum(dec_vals) extra = length - number_of_cells * cell_length - while extra < space_needed_for_decorations: + while extra < space_needed_for_decorations and number_of_cells > 0: number_of_cells -= 1 extra = length - number_of_cells * cell_length - cells_map = calculate_cells_map(bias, number_of_windows, number_of_cells) + cells_map = calculate_cells_map(bias, number_of_windows, number_of_cells) if number_of_cells > 0 else [0] * number_of_windows assert sum(cells_map) == number_of_cells extra = length - number_of_cells * cell_length - space_needed_for_decorations diff --git a/kitty_tests/layout.py b/kitty_tests/layout.py index cbcad2a0c..517ad5fd7 100644 --- a/kitty_tests/layout.py +++ b/kitty_tests/layout.py @@ -3,7 +3,7 @@ from kitty.config import defaults from kitty.fast_data_types import BOTTOM_EDGE, LEFT_EDGE, RIGHT_EDGE, TOP_EDGE, Region -from kitty.layout.base import lgd +from kitty.layout.base import layout_dimension, lgd from kitty.layout.interface import Grid, Horizontal, Splits, Stack, Tall from kitty.layout.splits import Pair from kitty.types import WindowGeometry @@ -325,6 +325,22 @@ class TestLayout(BaseTest): self.assertTrue(result) self.ae(root.bias, root_bias_before) + def test_layout_dimension_no_negative_cells(self): + # Regression test for issue #9946: when window padding exceeds the + # available space (e.g. after maximize sets a window to minimum width), + # layout_dimension must not produce a negative cells_per_window value + # which would cause right < left in the resulting window geometry. + for length, cell_length, decs in ( + (8, 8, [(5, 5)]), # padding (10) > length (8) > cell_length (8) + (6, 8, [(4, 4)]), # length < cell_length + (0, 8, [(4, 4)]), # zero length + (4, 8, [(3, 3)]), # space_needed == length, no room for cells + ): + result = next(layout_dimension(0, length, cell_length, decs)) + self.assertGreaterEqual(result.cells_per_window, 0, + f'cells_per_window={result.cells_per_window} < 0 for length={length}, ' + f'cell_length={cell_length}, decs={decs}') + def test_drag_resize_target_windows(self): # Helper: call drag_resize_target_windows with given window and edge flags. def drtw(q, all_windows, window, edges): From 4d55d306146ada0792fadb11cd41c43113491f41 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 15:05:34 +0000 Subject: [PATCH 2/2] Enhance regression test with additional geometry validity assertions Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/3b0c9eab-24ba-4934-a941-be477477cee4 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- kitty_tests/layout.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kitty_tests/layout.py b/kitty_tests/layout.py index 517ad5fd7..fb0802c3f 100644 --- a/kitty_tests/layout.py +++ b/kitty_tests/layout.py @@ -340,6 +340,14 @@ class TestLayout(BaseTest): self.assertGreaterEqual(result.cells_per_window, 0, f'cells_per_window={result.cells_per_window} < 0 for length={length}, ' f'cell_length={cell_length}, decs={decs}') + self.assertGreaterEqual(result.content_size, 0, + f'content_size={result.content_size} < 0 for length={length}, ' + f'cell_length={cell_length}, decs={decs}') + # content_pos must be within [0, length]: right edge = content_pos + content_size <= length + self.assertGreaterEqual(result.content_pos, 0) + self.assertLessEqual(result.content_pos + result.content_size, length, + f'right ({result.content_pos + result.content_size}) > length ({length}) for ' + f'cell_length={cell_length}, decs={decs}') def test_drag_resize_target_windows(self): # Helper: call drag_resize_target_windows with given window and edge flags.