From ecbd8ad7c0af8e0ef362804f35a2d6962eb94418 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Thu, 22 May 2025 20:48:51 -0400 Subject: [PATCH 1/4] Set explicit mainSectionWeight when forcing main view to full width Previously we were relying on setting just the sideSectionWeight in order to ensure the main panel was fully focused. This can cause a problem if the user had their `gui.sidePanelWidth` set to 1. Such a value make the mainPanelWidth = 0 by default. By just setting the sideSectionWeight, you then communicate to the UI that you want _both_ halves of the screen to have 0 width! No good! This change seems like it won't impact users of more standard `gui.sidePanelWidth` values, so it's just a free win! --- pkg/gui/controllers/helpers/window_arrangement_helper.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index 393b0ffb134..e4971ff965b 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -251,6 +251,7 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) { if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" { if args.ScreenMode == types.SCREEN_HALF || args.ScreenMode == types.SCREEN_FULL { sideSectionWeight = 0 + mainSectionWeight = 1 } } else { if args.ScreenMode == types.SCREEN_HALF { From f0b86bc2890576bbe2a0a51d4e44c453f0529cba Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Thu, 22 May 2025 20:58:14 -0400 Subject: [PATCH 2/4] Add explicit mainSectionWidth if it is 0 when main view focused Any time that we are on the `currentWindow == "main"` it makes sense for it to be visible, and this will ensure that --- pkg/gui/controllers/helpers/window_arrangement_helper.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index e4971ff965b..55c4b2c1726 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -252,6 +252,9 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) { if args.ScreenMode == types.SCREEN_HALF || args.ScreenMode == types.SCREEN_FULL { sideSectionWeight = 0 mainSectionWeight = 1 + } else if mainSectionWeight == 0 { + sideSectionWeight = 0 + mainSectionWeight = 1 } } else { if args.ScreenMode == types.SCREEN_HALF { From afe4808da976937c13ddf36be924b598200d4255 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Fri, 23 May 2025 17:23:27 -0400 Subject: [PATCH 3/4] fixup! Add explicit mainSectionWidth if it is 0 when main view focused --- pkg/gui/controllers/helpers/window_arrangement_helper.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index 55c4b2c1726..1bf00248b29 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -249,10 +249,7 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) { } if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" { - if args.ScreenMode == types.SCREEN_HALF || args.ScreenMode == types.SCREEN_FULL { - sideSectionWeight = 0 - mainSectionWeight = 1 - } else if mainSectionWeight == 0 { + if args.ScreenMode == types.SCREEN_HALF || args.ScreenMode == types.SCREEN_FULL || mainSectionWeight == 0 { sideSectionWeight = 0 mainSectionWeight = 1 } From 0ac3ac7e3e9b0d208af0ae865214081c08af4ea0 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Fri, 23 May 2025 17:30:13 -0400 Subject: [PATCH 4/4] Add tests for SidePanelWidth: 1 rendering of side panel and main I was unable to test the full flow that caused the crash from the initial bug report inside of window_arrangement_helper_test.go, so I created a full integration test. --- .../helpers/window_arrangement_helper_test.go | 81 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + .../tests/ui/side_panel_width_1.go | 29 +++++++ 3 files changed, 111 insertions(+) create mode 100644 pkg/integration/tests/ui/side_panel_width_1.go diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper_test.go b/pkg/gui/controllers/helpers/window_arrangement_helper_test.go index 6274fae2be6..207e0eb115b 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper_test.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper_test.go @@ -283,6 +283,87 @@ func TestGetWindowDimensions(t *testing.T) { B: information `, }, + { + name: "1.0 SidePanelWidth", + mutateArgs: func(args *WindowArrangementArgs) { + args.UserConfig.Gui.SidePanelWidth = 1.0 + }, + expected: ` + ╭status───────────────────────────────────────────────────────────────────╮ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + ╭files────────────────────────────────────────────────────────────────────╮ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + ╭branches─────────────────────────────────────────────────────────────────╮ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + ╭commits──────────────────────────────────────────────────────────────────╮ + │ │ + │ │ + │ │ + │ │ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + ╭stash────────────────────────────────────────────────────────────────────╮ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + A + A: statusSpacer1 + B: information + `, + }, + { + name: "1.0 SidePanelWidth main view focused", + mutateArgs: func(args *WindowArrangementArgs) { + args.UserConfig.Gui.SidePanelWidth = 1.0 + args.CurrentWindow = "main" + }, + expected: ` + ╭main─────────────────────────────────────────────────────────────────────╮ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + ╰─────────────────────────────────────────────────────────────────────────╯ + A + A: statusSpacer1 + B: information + `, + }, { name: "half screen mode, enlargedSideViewLocation left", mutateArgs: func(args *WindowArrangementArgs) { diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 23a05fa5c8a..2f8a88f2145 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -412,6 +412,7 @@ var tests = []*components.IntegrationTest{ ui.ModeSpecificKeybindingSuggestions, ui.OpenLinkFailure, ui.RangeSelect, + ui.SidePanelWidth1, ui.SwitchTabFromMenu, ui.SwitchTabWithPanelJumpKeys, undo.UndoCheckoutAndDrop, diff --git a/pkg/integration/tests/ui/side_panel_width_1.go b/pkg/integration/tests/ui/side_panel_width_1.go new file mode 100644 index 00000000000..a4d5fca29de --- /dev/null +++ b/pkg/integration/tests/ui/side_panel_width_1.go @@ -0,0 +1,29 @@ +package ui + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SidePanelWidth1 = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Verify that setting sidePanelWidth to 1.0 doesn't crash when navigating to commit files", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.SidePanelWidth = 1.0 + }, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file1.txt", "content") + shell.Commit("first commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits().Focus(). + Press(keys.Universal.NextScreenMode). + Press(keys.Universal.GoInto) + + t.Views().CommitFiles(). + Press(keys.Universal.GoInto) + + t.Views().PatchBuilding().Content(Contains("+content")) + }, +})