[sidePanelWidth]: Runtime error when value is 1.0
Describe the bug
When sidePanelWidth is set to 1.0, focusing preview window causes a runtime error
To Reproduce Steps to reproduce the behavior:
https://github.com/user-attachments/assets/4cfd7de6-cfdc-4463-8f4a-10fbd798c659
- Set config option
sidePanelWidthto 1.0 - Relaunch
lazygit, your 1-5 windows should take full width now - Press + key, which should display the preview window on the right that you normally see, when
sidePanelWidthhas default value - Select Commits window (number 4), press Enter on any commit and Enter again on any file in the commit
- Runtime error happens
Expected behavior
https://github.com/user-attachments/assets/7f7bfab8-4c9b-404d-af02-396647cc344f
Preview window should be focused as expected
Version info: commit=66caa25dcd4c247589e6adc71a6bc088678f3212, build date=2025-05-03T02:30:12Z, build source=binaryRelease, version=0.50.0, os=darwin, arch=arm64, git version=2.49.0
git version 2.49.0
Additional context
Error trace
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]: github.com/jesseduffield/lazycore/pkg/boxlayout.normalizeWeights({0x14000aff9f0, 0x2, 0x2}) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:161 +0x3d0 github.com/jesseduffield/lazycore/pkg/boxlayout.calcSizes({0x14000c385b0, 0x2, 0x14000f4ac78?}, 0x8d) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:97 +0x6c github.com/jesseduffield/lazycore/pkg/boxlayout.ArrangeWindows(0x14000c08280, 0x0, 0x0, 0x8d, 0x26) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:75 +0xe0 github.com/jesseduffield/lazycore/pkg/boxlayout.ArrangeWindows(0x14000f4b090, 0x0, 0x0, 0x8d, 0x27) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:86 +0x24c github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.GetWindowDimensions({0x8d, 0x27, 0x1400021f008, {0x100a73e7e, 0x4}, {0x100a73e7e, 0x4}, {0x100a760e5, 0x5}, 0x0, ...}) /home/runner/work/lazygit/lazygit/pkg/gui/controllers/helpers/window_arrangement_helper.go:168 +0x438 github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*WindowArrangementHelper).GetWindowDimensions(0x14000542100, {0x14000a30370, 0xa5}, {0x0, 0x0}) /home/runner/work/lazygit/lazygit/pkg/gui/controllers/helpers/window_arrangement_helper.go:106 +0x308 github.com/jesseduffield/lazygit/pkg/gui.(*Gui).getWindowDimensions(...) /home/runner/work/lazygit/lazygit/pkg/gui/gui.go:1134 github.com/jesseduffield/lazygit/pkg/gui.(*Gui).layout(0x14000240308, 0x14000270000) /home/runner/work/lazygit/lazygit/pkg/gui/layout.go:26 +0x10c github.com/jesseduffield/gocui.ManagerFunc.Layout(0x0?, 0x140017990a0?) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:728 +0x28 github.com/jesseduffield/gocui.(*Gui).flush(0x14000270000) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1185 +0xac github.com/jesseduffield/gocui.(*Gui).processEvent(0x14000270000) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:813 +0x208 github.com/jesseduffield/gocui.(*Gui).MainLoop(0x14000270000) /home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:778 +0x108 github.com/jesseduffield/lazygit/pkg/gui.(*Gui).Run(0x14000240308, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}}) /home/runner/work/lazygit/lazygit/pkg/gui/gui.go:867 +0x434 github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError.func1() /home/runner/work/lazygit/lazygit/pkg/gui/gui.go:873 +0x48 github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0x14000043928?) /home/runner/work/lazygit/lazygit/pkg/utils/utils.go:90 +0x5c github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError(0x14000240308, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}}) /home/runner/work/lazygit/lazygit/pkg/gui/gui.go:872 +0xc4 github.com/jesseduffield/lazygit/pkg/app.(*App).Run(...) /home/runner/work/lazygit/lazygit/pkg/app/app.go:270 github.com/jesseduffield/lazygit/pkg/app.Run({0x100e6bfb8?, 0x140000cc6e0?}, 0x140001f71c0, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}}) /home/runner/work/lazygit/lazygit/pkg/app/app.go:48 +0xb0 github.com/jesseduffield/lazygit/pkg/app.Start(0x14000043ef8, {0x0, 0x0}) /home/runner/work/lazygit/lazygit/pkg/app/entry_point.go:168 +0x9b0 main.main() /home/runner/work/lazygit/lazygit/main.go:23 +0x98
@mrmerc
Hey, thanks for the report! Easy to reproduce. I'm curious, is this an actual standard part of your flow, or did you just discover it while messing around?
I'm continuing to look into
@ChrisMcD1 hey, I rarely need the preview window, thus I tweaked the config option to make lazygit main windows fullscreen. Bug was discovered by accident.
Okay, interesting!
Well, the fix ended up being pretty easy in this case https://github.com/jesseduffield/lazygit/pull/4583
I also added a 2nd commit just now (while typing this) to that PR that also makes this behavior work on the main screen without you needing to press + to go to the split screen mode.
There might still be other problems with this setting choice. I don't think it's something that was truly intended 😅 A lot of stuff might subtly rely on the main view being visible. But if you're willing to be a bit of a trailblazer, good on ya!
Thank you for the fixes 😊
Hi, I'm running v0.56.0 and hitting this bug quite often 🙁.
I also have sidePanelWidth: 1 in config.
Typicaly I look inside some remote branch, select some file inside it, press Shift + + to show preview and then click inside the preview (when I want to select and copy something from the preview). Unfortunately lazygit crashes everytime after such action.
Here is the error stack:
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/jesseduffield/lazycore/pkg/boxlayout.normalizeWeights({0xc0032eac30, 0x2, 0x2})
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:161 +0x592
github.com/jesseduffield/lazycore/pkg/boxlayout.calcSizes({0xc006c2d470, 0x2, 0xc0032eacd8?}, 0x9a)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:97 +0x95
github.com/jesseduffield/lazycore/pkg/boxlayout.ArrangeWindows(0xc006bc9db0, 0x0, 0x0, 0x9a, 0x38)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:75 +0x117
github.com/jesseduffield/lazycore/pkg/boxlayout.ArrangeWindows(0xc0032eb0d8, 0x0, 0x0, 0x9a, 0x39)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/lazycore/pkg/boxlayout/boxlayout.go:86 +0x2e9
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.GetWindowDimensions({0x9a, 0x39, 0xc000140008, {0x7ff65fe338bf, 0x4}, {0x7ff65fe3b5c2, 0x8}, 0x0, 0x1, {0x0, ...}, ...})
/home/runner/work/lazygit/lazygit/pkg/gui/controllers/helpers/window_arrangement_helper.go:166 +0x4e7
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*WindowArrangementHelper).GetWindowDimensions(0xc000115700, {0xc006c6a210, 0xa5}, {0x0, 0x0})
/home/runner/work/lazygit/lazygit/pkg/gui/controllers/helpers/window_arrangement_helper.go:104 +0x3e5
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).getWindowDimensions(...)
/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:1112
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).layout(0xc0001d8008, 0xc0001dc000)
/home/runner/work/lazygit/lazygit/pkg/gui/layout.go:28 +0x145
github.com/jesseduffield/gocui.ManagerFunc.Layout(0x0?, 0xc006c741e0?)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:746 +0x19
github.com/jesseduffield/gocui.(*Gui).flush(0xc0001dc000)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:1203 +0xae
github.com/jesseduffield/gocui.(*Gui).processEvent(0xc0001dc000)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:831 +0x2cf
github.com/jesseduffield/gocui.(*Gui).MainLoop(0xc0001dc000)
/home/runner/work/lazygit/lazygit/vendor/github.com/jesseduffield/gocui/gui.go:796 +0xea
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).Run(0xc0001d8008, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:867 +0x511
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError.func1()
/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:873 +0x48
github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0xc0001d38e0?)
/home/runner/work/lazygit/lazygit/pkg/utils/utils.go:80 +0x56
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError(0xc0001d8008, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
/home/runner/work/lazygit/lazygit/pkg/gui/gui.go:872 +0xff
github.com/jesseduffield/lazygit/pkg/app.(*App).Run(...)
/home/runner/work/lazygit/lazygit/pkg/app/app.go:277
github.com/jesseduffield/lazygit/pkg/app.Run({0x7ff660025318?, 0xc0002c6160?}, 0xc000229800, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}})
/home/runner/work/lazygit/lazygit/pkg/app/app.go:48 +0xda
github.com/jesseduffield/lazygit/pkg/app.Start(0xc0001d3f00, {0x0, 0x0})
/home/runner/work/lazygit/lazygit/pkg/app/entry_point.go:177 +0xe05
main.main()
/home/runner/work/lazygit/lazygit/main.go:23 +0x98