mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-06-20 01:19:23 +02:00
Limit popup panel widths to a maximum width (#5231)
On very large screens they would get ridiculously wide. The limits we chose here are a little arbitrary: - 80 for confirmations and prompts - 90 for menus - auto-wrap width plus 25 for the commit message editor (or 100 if auto-wrap is off)
This commit is contained in:
@@ -125,10 +125,10 @@ func (self *ConfirmationHelper) getPopupPanelDimensionsAux(panelWidth int, panel
|
|||||||
height/2 + panelHeight/2
|
height/2 + panelHeight/2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) getPopupPanelWidth() int {
|
func (self *ConfirmationHelper) getPopupPanelWidth(maxWidth int) int {
|
||||||
width, _ := self.c.GocuiGui().Size()
|
width, _ := self.c.GocuiGui().Size()
|
||||||
// we want a minimum width up to a point, then we do it based on ratio.
|
// we want a minimum width up to a point, then we do it based on ratio, but only up to the given max width
|
||||||
panelWidth := 4 * width / 7
|
panelWidth := min(4*width/7, maxWidth)
|
||||||
minWidth := 80
|
minWidth := 80
|
||||||
if panelWidth < minWidth {
|
if panelWidth < minWidth {
|
||||||
panelWidth = min(width-2, minWidth)
|
panelWidth = min(width-2, minWidth)
|
||||||
@@ -328,7 +328,7 @@ func (self *ConfirmationHelper) resizeMenu(parentPopupContext types.Context) {
|
|||||||
// resize the window
|
// resize the window
|
||||||
itemCount := self.c.Contexts().Menu.UnfilteredLen()
|
itemCount := self.c.Contexts().Menu.UnfilteredLen()
|
||||||
offset := 3
|
offset := 3
|
||||||
panelWidth := self.getPopupPanelWidth()
|
panelWidth := self.getPopupPanelWidth(90)
|
||||||
contentWidth := panelWidth - 2 // minus 2 for the frame
|
contentWidth := panelWidth - 2 // minus 2 for the frame
|
||||||
promptLinesCount := self.layoutMenuPrompt(contentWidth)
|
promptLinesCount := self.layoutMenuPrompt(contentWidth)
|
||||||
x0, y0, x1, y1 := self.getPopupPanelDimensionsForContentHeight(panelWidth, itemCount+offset+promptLinesCount, parentPopupContext)
|
x0, y0, x1, y1 := self.getPopupPanelDimensionsForContentHeight(panelWidth, itemCount+offset+promptLinesCount, parentPopupContext)
|
||||||
@@ -375,7 +375,7 @@ func (self *ConfirmationHelper) layoutMenuPrompt(contentWidth int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) resizeConfirmationPanel(parentPopupContext types.Context) {
|
func (self *ConfirmationHelper) resizeConfirmationPanel(parentPopupContext types.Context) {
|
||||||
panelWidth := self.getPopupPanelWidth()
|
panelWidth := self.getPopupPanelWidth(80)
|
||||||
contentWidth := panelWidth - 2 // minus 2 for the frame
|
contentWidth := panelWidth - 2 // minus 2 for the frame
|
||||||
confirmationView := self.c.Views().Confirmation
|
confirmationView := self.c.Views().Confirmation
|
||||||
prompt := confirmationView.Buffer()
|
prompt := confirmationView.Buffer()
|
||||||
@@ -389,7 +389,7 @@ func (self *ConfirmationHelper) resizePromptPanel(parentPopupContext types.Conte
|
|||||||
if self.c.Views().Suggestions.Visible {
|
if self.c.Views().Suggestions.Visible {
|
||||||
suggestionsViewHeight = 11
|
suggestionsViewHeight = 11
|
||||||
}
|
}
|
||||||
panelWidth := self.getPopupPanelWidth()
|
panelWidth := self.getPopupPanelWidth(80)
|
||||||
contentWidth := panelWidth - 2 // minus 2 for the frame
|
contentWidth := panelWidth - 2 // minus 2 for the frame
|
||||||
promptView := self.c.Views().Prompt
|
promptView := self.c.Views().Prompt
|
||||||
prompt := promptView.TextArea.GetContent()
|
prompt := promptView.TextArea.GetContent()
|
||||||
@@ -403,7 +403,13 @@ func (self *ConfirmationHelper) resizePromptPanel(parentPopupContext types.Conte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) ResizeCommitMessagePanels(parentPopupContext types.Context) {
|
func (self *ConfirmationHelper) ResizeCommitMessagePanels(parentPopupContext types.Context) {
|
||||||
panelWidth := self.getPopupPanelWidth()
|
maxWidth := 100
|
||||||
|
if self.c.UserConfig().Git.Commit.AutoWrapCommitMessage {
|
||||||
|
// Adding some extra space to make it very obvious that we're wrapping the commit message
|
||||||
|
// for real, not just soft-wrapping for display at the window width.
|
||||||
|
maxWidth = self.c.UserConfig().Git.Commit.AutoWrapWidth + 25
|
||||||
|
}
|
||||||
|
panelWidth := self.getPopupPanelWidth(maxWidth)
|
||||||
content := self.c.Views().CommitDescription.TextArea.GetContent()
|
content := self.c.Views().CommitDescription.TextArea.GetContent()
|
||||||
summaryViewHeight := 3
|
summaryViewHeight := 3
|
||||||
panelHeight := getMessageHeight(false, true, content, panelWidth, self.c.Views().CommitDescription.TabWidth)
|
panelHeight := getMessageHeight(false, true, content, panelWidth, self.c.Views().CommitDescription.TabWidth)
|
||||||
|
|||||||
Reference in New Issue
Block a user