Skip to content

Commit f05f81d

Browse files
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 #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
2 parents e62aeb9 + 9d07404 commit f05f81d

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

โ€Žpkg/gui/controllers/helpers/window_arrangement_helper.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package helpers
22

33
import (
44
"fmt"
5+
"math"
56
"strings"
67

78
"github.com/jesseduffield/lazycore/pkg/boxlayout"
@@ -237,14 +238,14 @@ func mainSectionChildren(args WindowArrangementArgs) []*boxlayout.Box {
237238
}
238239

239240
func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
240-
// we originally specified this as a ratio i.e. .20 would correspond to a weight of 1 against 4
241241
sidePanelWidthRatio := args.UserConfig.Gui.SidePanelWidth
242-
// we could make this better by creating ratios like 2:3 rather than always 1:something
243-
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
244-
sideSectionWeight := 1
242+
// Using 120 so that the default of 0.3333 will remain consistent with previous behavior
243+
const maxColumnCount = 120
244+
mainSectionWeight := int(math.Round(maxColumnCount * (1 - sidePanelWidthRatio)))
245+
sideSectionWeight := int(math.Round(maxColumnCount * sidePanelWidthRatio))
245246

246247
if splitMainPanelSideBySide(args) {
247-
mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side
248+
mainSectionWeight = sideSectionWeight * 5 // need to shrink side panel to make way for main panels if side-by-side
248249
}
249250

250251
if args.CurrentWindow == "main" || args.CurrentWindow == "secondary" {
@@ -254,9 +255,9 @@ func getMidSectionWeights(args WindowArrangementArgs) (int, int) {
254255
} else {
255256
if args.ScreenMode == types.SCREEN_HALF {
256257
if args.UserConfig.Gui.EnlargedSideViewLocation == "top" {
257-
mainSectionWeight = 2
258+
mainSectionWeight = sideSectionWeight * 2
258259
} else {
259-
mainSectionWeight = 1
260+
mainSectionWeight = sideSectionWeight
260261
}
261262
} else if args.ScreenMode == types.SCREEN_FULL {
262263
mainSectionWeight = 0

โ€Žpkg/gui/controllers/helpers/window_arrangement_helper_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,86 @@ func TestGetWindowDimensions(t *testing.T) {
202202
B: information
203203
`,
204204
},
205+
{
206+
name: "0.5 SidePanelWidth",
207+
mutateArgs: func(args *WindowArrangementArgs) {
208+
args.UserConfig.Gui.SidePanelWidth = 0.5
209+
},
210+
expected: `
211+
โ•ญstatusโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ•ญmainโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
212+
โ”‚ โ”‚โ”‚ โ”‚
213+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
214+
โ•ญfilesโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
215+
โ”‚ โ”‚โ”‚ โ”‚
216+
โ”‚ โ”‚โ”‚ โ”‚
217+
โ”‚ โ”‚โ”‚ โ”‚
218+
โ”‚ โ”‚โ”‚ โ”‚
219+
โ”‚ โ”‚โ”‚ โ”‚
220+
โ”‚ โ”‚โ”‚ โ”‚
221+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
222+
โ•ญbranchesโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
223+
โ”‚ โ”‚โ”‚ โ”‚
224+
โ”‚ โ”‚โ”‚ โ”‚
225+
โ”‚ โ”‚โ”‚ โ”‚
226+
โ”‚ โ”‚โ”‚ โ”‚
227+
โ”‚ โ”‚โ”‚ โ”‚
228+
โ”‚ โ”‚โ”‚ โ”‚
229+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
230+
โ•ญcommitsโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
231+
โ”‚ โ”‚โ”‚ โ”‚
232+
โ”‚ โ”‚โ”‚ โ”‚
233+
โ”‚ โ”‚โ”‚ โ”‚
234+
โ”‚ โ”‚โ”‚ โ”‚
235+
โ”‚ โ”‚โ”‚ โ”‚
236+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
237+
โ•ญstashโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
238+
โ”‚ โ”‚โ”‚ โ”‚
239+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
240+
<optionsโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>A<Bโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>
241+
A: statusSpacer1
242+
B: information
243+
`,
244+
},
245+
{
246+
name: "0.8 SidePanelWidth",
247+
mutateArgs: func(args *WindowArrangementArgs) {
248+
args.UserConfig.Gui.SidePanelWidth = 0.8
249+
},
250+
expected: `
251+
โ•ญstatusโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ•ญmainโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
252+
โ”‚ โ”‚โ”‚ โ”‚
253+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
254+
โ•ญfilesโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
255+
โ”‚ โ”‚โ”‚ โ”‚
256+
โ”‚ โ”‚โ”‚ โ”‚
257+
โ”‚ โ”‚โ”‚ โ”‚
258+
โ”‚ โ”‚โ”‚ โ”‚
259+
โ”‚ โ”‚โ”‚ โ”‚
260+
โ”‚ โ”‚โ”‚ โ”‚
261+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
262+
โ•ญbranchesโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
263+
โ”‚ โ”‚โ”‚ โ”‚
264+
โ”‚ โ”‚โ”‚ โ”‚
265+
โ”‚ โ”‚โ”‚ โ”‚
266+
โ”‚ โ”‚โ”‚ โ”‚
267+
โ”‚ โ”‚โ”‚ โ”‚
268+
โ”‚ โ”‚โ”‚ โ”‚
269+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
270+
โ•ญcommitsโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
271+
โ”‚ โ”‚โ”‚ โ”‚
272+
โ”‚ โ”‚โ”‚ โ”‚
273+
โ”‚ โ”‚โ”‚ โ”‚
274+
โ”‚ โ”‚โ”‚ โ”‚
275+
โ”‚ โ”‚โ”‚ โ”‚
276+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ”‚ โ”‚
277+
โ•ญstashโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ”‚ โ”‚
278+
โ”‚ โ”‚โ”‚ โ”‚
279+
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
280+
<optionsโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>A<Bโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>
281+
A: statusSpacer1
282+
B: information
283+
`,
284+
},
205285
{
206286
name: "half screen mode, enlargedSideViewLocation left",
207287
mutateArgs: func(args *WindowArrangementArgs) {

0 commit comments

Comments
ย (0)