Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change side panel width calculation to work for larger numbers #4287

Merged
merged 1 commit into from
Feb 23, 2025

Conversation

ChrisMcD1
Copy link
Contributor

  • 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
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

} else {
mainSectionWeight = 1
mainSectionWeight = sideSectionWeight
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all be equivalent (and are if the tests prove anything), since the mainSectionWeight was always compared to the static side section 1 before. It will maintain its 1:1 and 1:2 ratios with this code.

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, one question

// we could make this better by creating ratios like 2:3 rather than always 1:something
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
sideSectionWeight := 1
// Using 24 so that the default of 0.3333 will remain consistent with previous behavior
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that we want this number to have many factors? If so, how about we add 5 as a factor to it to make 120?

Also we should have this value assigned to a variable rather than duplicate it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the idea is to make it have many factors.

Moved the value to a constant, and made it 120. I am still a bit confused what happened when I first wrote this where having the const multiplier be too high broke the gui, but that doesn't seem to be the case for 120!

@ChrisMcD1
Copy link
Contributor Author

Ah, shifting to 120 changed the 0.8 test I wrote marginally. Fixed!

@ChrisMcD1 ChrisMcD1 force-pushed the 3721-sidePanelWidth branch 2 times, most recently from 32e18cd to 2f03526 Compare February 23, 2025 17:08
@ChrisMcD1
Copy link
Contributor Author

@jesseduffield Fixed up the broken tests (again). I didn't notice the pipelines were failing because the failing check-required-label check makes all of my PRs have a red X on them from the overview screen. Is there some way I can add a bug label to this PR to get that check passing? I think I am lacking permissions to do that.

@stefanhaller stefanhaller added the bug Something isn't working label Feb 23, 2025
@jesseduffield
Copy link
Owner

@ChrisMcD1 for now, Stefan and I can handle the labels as one of us is going to be reviewing your PRs

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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
@jesseduffield jesseduffield merged commit f05f81d into jesseduffield:master Feb 23, 2025
15 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | patch | `v0.47.1` -> `v0.47.2` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.47.2`](https://github.com/jesseduffield/lazygit/releases/tag/v0.47.2)

[Compare Source](jesseduffield/lazygit@v0.47.1...v0.47.2)

<!-- Release notes generated using configuration in .github/release.yml at v0.47.2 -->

Small patch release for you all. This is mainly to fix an issue with v0.47.1 which erroneously re-indented users' lazygit config files on startup.

Shout-out to [@&#8203;karimkhaleel](https://github.com/karimkhaleel) for his MR with some gnarly yaml-handling code.

And a special shout-out to [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) who has been pumping out many great contributions lately. Great to have you aboard.

#### What's Changed

##### Enhancements 🔥

-   Skip post-checkout hook when discarding changes by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4313

##### Fixes 🔧

-   fix: Disable global keybinds when confirmation is active by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4284
-   Don't rewrite config file unnecessarily when it contains commitPrefixes by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4311
-   Change side panel width calculation to work for larger numbers by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4287

##### Maintenance ⚙️

-   Fix auto-release schedule by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4308
-   Use indentation of 2 when rewriting auto-migrated config file by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4312
-   Use refs in jsonschema by [@&#8203;karimkhaleel](https://github.com/karimkhaleel) in jesseduffield/lazygit#4309
-   Improve release workflow by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4307
-   Filter out dev comments from schema by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4319
-   Fix release script by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4322
-   Fix release script once again by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4323

##### Docs 📖

-   Improve the error message when users have gpg signing turned on by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4296

**Full Changelog**: jesseduffield/lazygit@v0.47.1...v0.47.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODAuMiIsInVwZGF0ZWRJblZlciI6IjM5LjE4MC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sidePanelWidth buggy
3 participants