mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Change side panel width calculation to work for larger numbers (#4287)
- **PR Description** The current implementation of calculating sidePanelWidths does not support any number higher than 0.5. Past that point, `mainSectionWidth` will always be 0 because `1/0.6` = 1.6666 which gets truncated to 1, which minus 1 is 0. This PR proposes an alternative way, which effectively just splits the horizontal range into 24 boxes, and the range from 0 to 1 dictates what percentage of the boxes they get. I think this matches what the docs have always claimed, which is: ``` Fraction of the total screen width to use for the left side section. ``` The number 24 was chosen intentionally so that the default users of 0.33333 will not see any changes in their behavior. Users of the primary numbers 0.2, 0.15, and 0.1 will still retain their ratios too! (by sheer coincidence). There is one technical thing that I do not understand. On the first implementation of this, I chose to make the ratio 1000, which broke the entire thing. The outputs were not evenly distributed at all, with a tiny jump from 0.7 to 0.8, but a huge jump to 0.9. > Note: While writing up this PR, I tried to re-test this and I couldn't reproduce... I'm leaving this in here just because it was an oddity. And looking at the downstream `normalizeWeights` function, there clearly is some work to find the lowest common factor, which would get trickier when comparing 567 and 433. Is doing the computations on the Weight 24 something we should worry about for some reason? Fixes https://github.com/jesseduffield/lazygit/issues/3721 - **Please check if the PR fulfills these requirements** * [X] Cheatsheets are up-to-date (run `go generate ./...`) * [X] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [X] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [X] You've read through your own file changes for silly mistakes etc
This commit is contained in:
commit
f05f81d713
2 changed files with 88 additions and 7 deletions
|
@ -2,6 +2,7 @@ package helpers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazycore/pkg/boxlayout"
|
||||
|
@ -237,14 +238,14 @@ func mainSectionChildren(args WindowArrangementArgs) []*boxlayout.Box {
|
|||
}
|
||||
|
||||
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
|
||||
// we could make this better by creating ratios like 2:3 rather than always 1:something
|
||||
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
|
||||
sideSectionWeight := 1
|
||||
// Using 120 so that the default of 0.3333 will remain consistent with previous behavior
|
||||
const maxColumnCount = 120
|
||||
mainSectionWeight := int(math.Round(maxColumnCount * (1 - sidePanelWidthRatio)))
|
||||
sideSectionWeight := int(math.Round(maxColumnCount * sidePanelWidthRatio))
|
||||
|
||||
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" {
|
||||
|
@ -254,9 +255,9 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
|
|||
} else {
|
||||
if args.ScreenMode == types.SCREEN_HALF {
|
||||
if args.UserConfig.Gui.EnlargedSideViewLocation == "top" {
|
||||
mainSectionWeight = 2
|
||||
mainSectionWeight = sideSectionWeight * 2
|
||||
} else {
|
||||
mainSectionWeight = 1
|
||||
mainSectionWeight = sideSectionWeight
|
||||
}
|
||||
} else if args.ScreenMode == types.SCREEN_FULL {
|
||||
mainSectionWeight = 0
|
||||
|
|
|
@ -202,6 +202,86 @@ func TestGetWindowDimensions(t *testing.T) {
|
|||
B: information
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "0.5 SidePanelWidth",
|
||||
mutateArgs: func(args *WindowArrangementArgs) {
|
||||
args.UserConfig.Gui.SidePanelWidth = 0.5
|
||||
},
|
||||
expected: `
|
||||
╭status──────────────────────────────╮╭main───────────────────────────────╮
|
||||
│ ││ │
|
||||
╰────────────────────────────────────╯│ │
|
||||
╭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: `
|
||||
╭status────────────────────────────────────────────────────╮╭main─────────╮
|
||||
│ ││ │
|
||||
╰──────────────────────────────────────────────────────────╯│ │
|
||||
╭files─────────────────────────────────────────────────────╮│ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
╰──────────────────────────────────────────────────────────╯│ │
|
||||
╭branches──────────────────────────────────────────────────╮│ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
╰──────────────────────────────────────────────────────────╯│ │
|
||||
╭commits───────────────────────────────────────────────────╮│ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
╰──────────────────────────────────────────────────────────╯│ │
|
||||
╭stash─────────────────────────────────────────────────────╮│ │
|
||||
│ ││ │
|
||||
╰──────────────────────────────────────────────────────────╯╰─────────────╯
|
||||
<options──────────────────────────────────────────────────────>A<B────────>
|
||||
A: statusSpacer1
|
||||
B: information
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "half screen mode, enlargedSideViewLocation left",
|
||||
mutateArgs: func(args *WindowArrangementArgs) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue