1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-10 23:57:43 +02:00

Change side panel width calculation to work for larger numbers

This technically is a breaking change for some existing numbers,
but it stays the same for default case, and isn't much different for
others
This commit is contained in:
Chris McDonnell 2025-02-19 00:19:59 -05:00 committed by Jesse Duffield
parent e62aeb99ed
commit 9d0740427e
2 changed files with 88 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package helpers
import ( import (
"fmt" "fmt"
"math"
"strings" "strings"
"github.com/jesseduffield/lazycore/pkg/boxlayout" "github.com/jesseduffield/lazycore/pkg/boxlayout"
@ -237,14 +238,14 @@ func mainSectionChildren(args WindowArrangementArgs) []*boxlayout.Box {
} }
func getMidSectionWeights(args WindowArrangementArgs) (int, int) { func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
// we originally specified this as a ratio i.e. .20 would correspond to a weight of 1 against 4
sidePanelWidthRatio := args.UserConfig.Gui.SidePanelWidth sidePanelWidthRatio := args.UserConfig.Gui.SidePanelWidth
// we could make this better by creating ratios like 2:3 rather than always 1:something // Using 120 so that the default of 0.3333 will remain consistent with previous behavior
mainSectionWeight := int(1/sidePanelWidthRatio) - 1 const maxColumnCount = 120
sideSectionWeight := 1 mainSectionWeight := int(math.Round(maxColumnCount * (1 - sidePanelWidthRatio)))
sideSectionWeight := int(math.Round(maxColumnCount * sidePanelWidthRatio))
if splitMainPanelSideBySide(args) { if splitMainPanelSideBySide(args) {
mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side mainSectionWeight = sideSectionWeight * 5 // need to shrink side panel to make way for main panels if side-by-side
} }
if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" { if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" {
@ -254,9 +255,9 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
} else { } else {
if args.ScreenMode == types.SCREEN_HALF { if args.ScreenMode == types.SCREEN_HALF {
if args.UserConfig.Gui.EnlargedSideViewLocation == "top" { if args.UserConfig.Gui.EnlargedSideViewLocation == "top" {
mainSectionWeight = 2 mainSectionWeight = sideSectionWeight * 2
} else { } else {
mainSectionWeight = 1 mainSectionWeight = sideSectionWeight
} }
} else if args.ScreenMode == types.SCREEN_FULL { } else if args.ScreenMode == types.SCREEN_FULL {
mainSectionWeight = 0 mainSectionWeight = 0

View File

@ -202,6 +202,86 @@ func TestGetWindowDimensions(t *testing.T) {
B: information B: information
`, `,
}, },
{
name: "0.5 SidePanelWidth",
mutateArgs: func(args *WindowArrangementArgs) {
args.UserConfig.Gui.SidePanelWidth = 0.5
},
expected: `
statusmain
files
branches
commits
stash
<options>A<B>
A: statusSpacer1
B: information
`,
},
{
name: "0.8 SidePanelWidth",
mutateArgs: func(args *WindowArrangementArgs) {
args.UserConfig.Gui.SidePanelWidth = 0.8
},
expected: `
statusmain
files
branches
commits
stash
<options>A<B>
A: statusSpacer1
B: information
`,
},
{ {
name: "half screen mode, enlargedSideViewLocation left", name: "half screen mode, enlargedSideViewLocation left",
mutateArgs: func(args *WindowArrangementArgs) { mutateArgs: func(args *WindowArrangementArgs) {