mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-21 04:46:29 +03:00
Let the user resize the side panels by dragging them with the mouse
The only way to change the width of the side panels was the gui.sidePanelWidth config. Finding a good value took some trial and error, a value didn't work well across very different screen widths, and it had no effect in half screen mode. The user can now drag the boundary between the side panels and the main view with the mouse. The boundary consists of the right edges of the side panels and the left edges of the main view and the command log, so it is two columns wide (or two rows high if the side panels are above the main view). While the mouse hovers over it, it is drawn with heavy lines, and the bottom line says that it can be dragged. A double click resets the size to the default. A single click does nothing. The size is saved in state.yml when the drag ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c65e78b37
commit
9d098bb8a0
13 files changed
+597
-1
No files matched your search
@@ -73,6 +73,7 @@ func (gui *Gui) resetHelpersAndControllers() {
|
||||
)
|
||||
bisectHelper := helpers.NewBisectHelper(helperCommon)
|
||||
windowHelper := helpers.NewWindowHelper(helperCommon, viewHelper)
|
||||
confirmationHelper := helpers.NewConfirmationHelper(helperCommon)
|
||||
modeHelper := helpers.NewModeHelper(
|
||||
helperCommon,
|
||||
diffHelper,
|
||||
@@ -115,10 +116,11 @@ func (gui *Gui) resetHelpersAndControllers() {
|
||||
Window: windowHelper,
|
||||
View: viewHelper,
|
||||
Refresh: refreshHelper,
|
||||
Confirmation: helpers.NewConfirmationHelper(helperCommon),
|
||||
Confirmation: confirmationHelper,
|
||||
Mode: modeHelper,
|
||||
AppStatus: appStatusHelper,
|
||||
InlineStatus: helpers.NewInlineStatusHelper(helperCommon, windowHelper),
|
||||
SidePanelResize: helpers.NewSidePanelResizeHelper(helperCommon, windowHelper, confirmationHelper),
|
||||
WindowArrangement: helpers.NewWindowArrangementHelper(
|
||||
gui.c,
|
||||
windowHelper,
|
||||
|
||||
@@ -50,6 +50,7 @@ type Helpers struct {
|
||||
AppStatus *AppStatusHelper
|
||||
InlineStatus *InlineStatusHelper
|
||||
WindowArrangement *WindowArrangementHelper
|
||||
SidePanelResize *SidePanelResizeHelper
|
||||
Search *SearchHelper
|
||||
Worktree *WorktreeHelper
|
||||
SubCommits *SubCommitsHelper
|
||||
@@ -87,6 +88,7 @@ func NewStubHelpers() *Helpers {
|
||||
AppStatus: &AppStatusHelper{},
|
||||
InlineStatus: &InlineStatusHelper{},
|
||||
WindowArrangement: &WindowArrangementHelper{},
|
||||
SidePanelResize: &SidePanelResizeHelper{},
|
||||
Search: &SearchHelper{},
|
||||
Worktree: &WorktreeHelper{},
|
||||
SubCommits: &SubCommitsHelper{},
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/lazycore/pkg/boxlayout"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||
)
|
||||
|
||||
// SidePanelResizeHelper lets the user resize the side panels by dragging the
|
||||
// boundary between them and the main view with the mouse. The boundary consists
|
||||
// of the edges of the side panels that face the main view and the edges of the
|
||||
// main view and the command log that face the side panels, so it is two columns
|
||||
// wide (or two rows high if the side panels are above the main view).
|
||||
type SidePanelResizeHelper struct {
|
||||
c *HelperCommon
|
||||
windowHelper *WindowHelper
|
||||
confirmationHelper *ConfirmationHelper
|
||||
|
||||
// The boundary as of the last layout; nil if only the side panels or only
|
||||
// the main view are visible
|
||||
boundary *sidePanelBoundary
|
||||
|
||||
// The last known position of the mouse pointer
|
||||
pointerKnown bool
|
||||
pointerX, pointerY int
|
||||
hovering bool
|
||||
|
||||
dragging bool
|
||||
dragLayout config.SidePanelLayout
|
||||
// The size of the side panels that the drag has set, and the screen size
|
||||
// it refers to; 0 if the drag hasn't changed the size yet
|
||||
dragSize, dragScreenSize int
|
||||
// The sizes for dragLayout before the drag started
|
||||
sizesBeforeDrag []config.SidePanelSize
|
||||
// Where in the boundary the drag started: 0 for the column (or row) of the
|
||||
// side panels, 1 for the one of the main view
|
||||
grabOffset int
|
||||
// When the user last pressed the mouse button on the boundary without
|
||||
// dragging it; zero if the press doesn't count towards a double click
|
||||
lastClickTime time.Time
|
||||
}
|
||||
|
||||
type sidePanelBoundary struct {
|
||||
arrangement SidePanelArrangement
|
||||
// The last column (or row) of the side panels. The boundary consists of
|
||||
// this one and the next one.
|
||||
pos int
|
||||
// The first and the last row (or column) of the boundary
|
||||
start, end int
|
||||
sideViews []*gocui.View
|
||||
mainViews []*gocui.View
|
||||
}
|
||||
|
||||
func NewSidePanelResizeHelper(
|
||||
c *HelperCommon,
|
||||
windowHelper *WindowHelper,
|
||||
confirmationHelper *ConfirmationHelper,
|
||||
) *SidePanelResizeHelper {
|
||||
return &SidePanelResizeHelper{
|
||||
c: c,
|
||||
windowHelper: windowHelper,
|
||||
confirmationHelper: confirmationHelper,
|
||||
}
|
||||
}
|
||||
|
||||
// coordinates returns the given screen position as a coordinate across the
|
||||
// boundary and one along it.
|
||||
func (self *sidePanelBoundary) coordinates(x, y int) (across int, along int) {
|
||||
if self.arrangement.SidePanelsAbove {
|
||||
return y, x
|
||||
}
|
||||
return x, y
|
||||
}
|
||||
|
||||
func (self *sidePanelBoundary) contains(x, y int) bool {
|
||||
across, along := self.coordinates(x, y)
|
||||
return (across == self.pos || across == self.pos+1) && along >= self.start && along <= self.end
|
||||
}
|
||||
|
||||
// IsActive returns true while the mouse hovers over the boundary or drags it.
|
||||
func (self *SidePanelResizeHelper) IsActive() bool {
|
||||
return self.boundary != nil && (self.hovering || self.dragging)
|
||||
}
|
||||
|
||||
// Layout finds the boundary after the views have been laid out, and highlights
|
||||
// it while the mouse hovers over it or drags it.
|
||||
func (self *SidePanelResizeHelper) Layout(
|
||||
windowDimensions map[string]boxlayout.Dimensions,
|
||||
arrangement SidePanelArrangement,
|
||||
hasArrangement bool,
|
||||
) {
|
||||
self.boundary = nil
|
||||
if hasArrangement {
|
||||
self.boundary = self.findBoundary(windowDimensions, arrangement)
|
||||
}
|
||||
self.updateHovering()
|
||||
self.highlightBoundary()
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) OnMouseMove(x, y int) {
|
||||
self.pointerKnown = true
|
||||
self.pointerX, self.pointerY = x, y
|
||||
self.updateHovering()
|
||||
}
|
||||
|
||||
// OnFocusLost stops highlighting the boundary. The terminal doesn't report it
|
||||
// when the pointer leaves its window, so if the pointer leaves the window right
|
||||
// from the boundary, the boundary stays highlighted until the window loses focus
|
||||
// or the pointer comes back.
|
||||
func (self *SidePanelResizeHelper) OnFocusLost() {
|
||||
self.pointerKnown = false
|
||||
self.updateHovering()
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) updateHovering() {
|
||||
self.hovering = self.pointerKnown &&
|
||||
self.boundary != nil &&
|
||||
!self.confirmationHelper.IsPopupPanelFocused() &&
|
||||
self.boundary.contains(self.pointerX, self.pointerY)
|
||||
}
|
||||
|
||||
// InterceptMouse handles the mouse events of gestures that start on the
|
||||
// boundary; see gocui.Gui.InterceptMouse.
|
||||
func (self *SidePanelResizeHelper) InterceptMouse(ev gocui.MouseEvent) bool {
|
||||
switch {
|
||||
case ev.Key == gocui.MouseLeft && ev.Mod == gocui.ModNone:
|
||||
return self.onPress(ev)
|
||||
case ev.Key == gocui.MouseLeft && ev.Mod == gocui.ModMotion:
|
||||
return self.onDrag(ev)
|
||||
case ev.Key == gocui.MouseRelease:
|
||||
return self.onRelease(ev)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) onPress(ev gocui.MouseEvent) bool {
|
||||
boundary := self.boundary
|
||||
if boundary == nil ||
|
||||
self.confirmationHelper.IsPopupPanelFocused() ||
|
||||
!boundary.contains(ev.X, ev.Y) {
|
||||
return false
|
||||
}
|
||||
|
||||
self.pointerKnown = true
|
||||
self.pointerX, self.pointerY = ev.X, ev.Y
|
||||
layout := boundary.arrangement.Layout
|
||||
|
||||
if !self.lastClickTime.IsZero() && ev.When.Sub(self.lastClickTime) < gocui.DOUBLE_CLICK_THRESHOLD {
|
||||
self.lastClickTime = time.Time{}
|
||||
self.resetSizes(layout)
|
||||
return true
|
||||
}
|
||||
|
||||
across, _ := boundary.coordinates(ev.X, ev.Y)
|
||||
self.dragging = true
|
||||
self.dragSize, self.dragScreenSize = 0, 0
|
||||
self.dragLayout = layout
|
||||
self.sizesBeforeDrag = self.c.State().GetSidePanelSizes()[layout]
|
||||
self.grabOffset = across - boundary.pos
|
||||
self.lastClickTime = ev.When
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) onDrag(ev gocui.MouseEvent) bool {
|
||||
if !self.dragging {
|
||||
return false
|
||||
}
|
||||
|
||||
self.pointerX, self.pointerY = ev.X, ev.Y
|
||||
boundary := self.boundary
|
||||
if boundary == nil || boundary.arrangement.Layout != self.dragLayout {
|
||||
// The layout changed under the drag, e.g. because a refresh split the
|
||||
// main view. Ignore the rest of the gesture.
|
||||
return true
|
||||
}
|
||||
|
||||
// Several events can be handled before the next layout, so the boundary
|
||||
// may not show the size of the previous drag event yet.
|
||||
currentSize := boundary.pos + 1
|
||||
if self.dragSize != 0 {
|
||||
currentSize = self.dragSize
|
||||
}
|
||||
across, _ := boundary.coordinates(ev.X, ev.Y)
|
||||
screenSize := boundary.arrangement.ScreenSize
|
||||
size := clampSideSectionSize(across-self.grabOffset+1, screenSize)
|
||||
if size == currentSize {
|
||||
return true
|
||||
}
|
||||
|
||||
self.dragSize, self.dragScreenSize = size, screenSize
|
||||
self.lastClickTime = time.Time{}
|
||||
self.setSizes(self.dragLayout, recordSidePanelSize(self.sizesBeforeDrag, screenSize, size))
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) onRelease(ev gocui.MouseEvent) bool {
|
||||
if !self.dragging {
|
||||
return false
|
||||
}
|
||||
|
||||
self.dragging = false
|
||||
self.pointerX, self.pointerY = ev.X, ev.Y
|
||||
self.updateHovering()
|
||||
|
||||
if self.dragSize != 0 {
|
||||
layout, screenSize, size := self.dragLayout, self.dragScreenSize, self.dragSize
|
||||
self.c.UpdateAppState(func(state *config.AppState) {
|
||||
if state.SidePanelSizes == nil {
|
||||
state.SidePanelSizes = map[config.SidePanelLayout][]config.SidePanelSize{}
|
||||
}
|
||||
sizes := ValidSidePanelSizes(state.SidePanelSizes)[layout]
|
||||
state.SidePanelSizes[layout] = recordSidePanelSize(sizes, screenSize, size)
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// resetSizes forgets the sizes that the user set for the given layout, so that
|
||||
// the default applies again.
|
||||
func (self *SidePanelResizeHelper) resetSizes(layout config.SidePanelLayout) {
|
||||
self.setSizes(layout, nil)
|
||||
self.c.UpdateAppState(func(state *config.AppState) {
|
||||
delete(state.SidePanelSizes, layout)
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) setSizes(layout config.SidePanelLayout, sizes []config.SidePanelSize) {
|
||||
sizesByLayout := maps.Clone(self.c.State().GetSidePanelSizes())
|
||||
if sizesByLayout == nil {
|
||||
sizesByLayout = map[config.SidePanelLayout][]config.SidePanelSize{}
|
||||
}
|
||||
if len(sizes) == 0 {
|
||||
delete(sizesByLayout, layout)
|
||||
} else {
|
||||
sizesByLayout[layout] = sizes
|
||||
}
|
||||
self.c.State().SetSidePanelSizes(sizesByLayout)
|
||||
}
|
||||
|
||||
type windowView struct {
|
||||
dimensions boxlayout.Dimensions
|
||||
view *gocui.View
|
||||
}
|
||||
|
||||
// visibleWindowViews returns the views shown in the given windows, if the
|
||||
// windows take up any space.
|
||||
func (self *SidePanelResizeHelper) visibleWindowViews(
|
||||
windowDimensions map[string]boxlayout.Dimensions,
|
||||
windows []string,
|
||||
) []windowView {
|
||||
result := []windowView{}
|
||||
for _, window := range windows {
|
||||
dimensions, ok := windowDimensions[window]
|
||||
if !ok || dimensions.X1 < dimensions.X0 || dimensions.Y1 < dimensions.Y0 {
|
||||
continue
|
||||
}
|
||||
view, err := self.c.GocuiGui().View(self.windowHelper.GetViewNameForWindow(window))
|
||||
if err != nil || !view.Visible {
|
||||
continue
|
||||
}
|
||||
result = append(result, windowView{dimensions: dimensions, view: view})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) findBoundary(
|
||||
windowDimensions map[string]boxlayout.Dimensions,
|
||||
arrangement SidePanelArrangement,
|
||||
) *sidePanelBoundary {
|
||||
sideWindowViews := self.visibleWindowViews(windowDimensions, self.windowHelper.SideWindows())
|
||||
mainWindowViews := self.visibleWindowViews(windowDimensions, []string{"main", "secondary", "extras"})
|
||||
if len(sideWindowViews) == 0 || len(mainWindowViews) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// The coordinates of a window across the boundary, and along it
|
||||
extent := func(d boxlayout.Dimensions) (across0, across1, along0, along1 int) {
|
||||
if arrangement.SidePanelsAbove {
|
||||
return d.Y0, d.Y1, d.X0, d.X1
|
||||
}
|
||||
return d.X0, d.X1, d.Y0, d.Y1
|
||||
}
|
||||
|
||||
boundary := &sidePanelBoundary{arrangement: arrangement, pos: -1, start: -1, end: -1}
|
||||
for _, w := range sideWindowViews {
|
||||
_, across1, _, _ := extent(w.dimensions)
|
||||
boundary.pos = max(boundary.pos, across1)
|
||||
}
|
||||
addAlong := func(along0, along1 int) {
|
||||
if boundary.start == -1 || along0 < boundary.start {
|
||||
boundary.start = along0
|
||||
}
|
||||
boundary.end = max(boundary.end, along1)
|
||||
}
|
||||
for _, w := range sideWindowViews {
|
||||
_, across1, along0, along1 := extent(w.dimensions)
|
||||
if across1 == boundary.pos {
|
||||
boundary.sideViews = append(boundary.sideViews, w.view)
|
||||
addAlong(along0, along1)
|
||||
}
|
||||
}
|
||||
for _, w := range mainWindowViews {
|
||||
across0, _, along0, along1 := extent(w.dimensions)
|
||||
if across0 == boundary.pos+1 {
|
||||
boundary.mainViews = append(boundary.mainViews, w.view)
|
||||
addAlong(along0, along1)
|
||||
}
|
||||
}
|
||||
if len(boundary.mainViews) == 0 {
|
||||
return nil
|
||||
}
|
||||
return boundary
|
||||
}
|
||||
|
||||
func (self *SidePanelResizeHelper) highlightBoundary() {
|
||||
for _, view := range self.c.GocuiGui().Views() {
|
||||
view.EdgeHighlight = nil
|
||||
}
|
||||
if !self.IsActive() {
|
||||
return
|
||||
}
|
||||
|
||||
for _, view := range self.boundary.sideViews {
|
||||
view.EdgeHighlight = self.edgeHighlight(true)
|
||||
}
|
||||
for _, view := range self.boundary.mainViews {
|
||||
view.EdgeHighlight = self.edgeHighlight(false)
|
||||
}
|
||||
}
|
||||
|
||||
// edgeHighlight returns the highlight for the edge of a side view or a main view
|
||||
// that is part of the boundary. It draws the edge with heavy lines, and uses
|
||||
// corners that join them to the light lines of the rest of the frame. There are
|
||||
// no such corners for double or bold lines, so with these borders it only
|
||||
// changes the color of the edge.
|
||||
func (self *SidePanelResizeHelper) edgeHighlight(isSideView bool) *gocui.EdgeHighlight {
|
||||
highlight := &gocui.EdgeHighlight{Color: theme.ActiveBorderColor}
|
||||
above := self.boundary.arrangement.SidePanelsAbove
|
||||
switch {
|
||||
case !above && isSideView:
|
||||
highlight.Edge = gocui.EdgeRight
|
||||
case !above:
|
||||
highlight.Edge = gocui.EdgeLeft
|
||||
case isSideView:
|
||||
highlight.Edge = gocui.EdgeBottom
|
||||
default:
|
||||
highlight.Edge = gocui.EdgeTop
|
||||
}
|
||||
|
||||
switch self.c.UserConfig().Gui.Border {
|
||||
case "single", "rounded":
|
||||
switch highlight.Edge {
|
||||
case gocui.EdgeRight:
|
||||
highlight.Rune, highlight.StartCorner, highlight.EndCorner = '┃', '┒', '┚'
|
||||
case gocui.EdgeLeft:
|
||||
highlight.Rune, highlight.StartCorner, highlight.EndCorner = '┃', '┎', '┖'
|
||||
case gocui.EdgeBottom:
|
||||
highlight.Rune, highlight.StartCorner, highlight.EndCorner = '━', '┕', '┙'
|
||||
case gocui.EdgeTop:
|
||||
highlight.Rune, highlight.StartCorner, highlight.EndCorner = '━', '┍', '┑'
|
||||
}
|
||||
case "hidden":
|
||||
// The frame is invisible, so draw just the edge
|
||||
highlight.Rune = '┃'
|
||||
if above {
|
||||
highlight.Rune = '━'
|
||||
}
|
||||
highlight.StartCorner, highlight.EndCorner = highlight.Rune, highlight.Rune
|
||||
}
|
||||
return highlight
|
||||
}
|
||||
@@ -47,6 +47,28 @@ func sidePanelSizeForScreen(sizes []config.SidePanelSize, screenSize int) (int,
|
||||
return int(math.Round(lowerSize + t*(upperSize-lowerSize))), true
|
||||
}
|
||||
|
||||
// recordSidePanelSize returns sizes plus the size that the user set at the given
|
||||
// screen size. It replaces the sizes for similar screen sizes, so that e.g.
|
||||
// zooming the terminal's font in or out by a step doesn't keep adding sizes.
|
||||
func recordSidePanelSize(sizes []config.SidePanelSize, screenSize int, size int) []config.SidePanelSize {
|
||||
result := lo.Reject(sizes, func(existing config.SidePanelSize, _ int) bool {
|
||||
return isSimilarScreenSize(existing.ScreenSize, screenSize)
|
||||
})
|
||||
// Four decimals are enough to get the same size back for any realistic
|
||||
// screen size, and they keep state.yml readable.
|
||||
ratio := math.Round(float64(size)/float64(screenSize)*10000) / 10000
|
||||
result = append(result, config.SidePanelSize{ScreenSize: screenSize, Ratio: ratio})
|
||||
slices.SortFunc(result, func(a, b config.SidePanelSize) int {
|
||||
return a.ScreenSize - b.ScreenSize
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
// isSimilarScreenSize returns true if the two screen sizes differ by at most 15%.
|
||||
func isSimilarScreenSize(a int, b int) bool {
|
||||
return float64(max(a, b)) <= float64(min(a, b))*1.15
|
||||
}
|
||||
|
||||
func clampSideSectionSize(size int, screenSize int) int {
|
||||
return max(minSideSectionSize, min(size, screenSize-minSideSectionSize))
|
||||
}
|
||||
|
||||
@@ -93,6 +93,91 @@ func TestSidePanelSizeForScreen(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordSidePanelSize(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
sizes []config.SidePanelSize
|
||||
screenSize int
|
||||
size int
|
||||
expected []config.SidePanelSize
|
||||
}{
|
||||
{
|
||||
name: "first size",
|
||||
sizes: nil,
|
||||
screenSize: 160,
|
||||
size: 50,
|
||||
expected: []config.SidePanelSize{{ScreenSize: 160, Ratio: 0.3125}},
|
||||
},
|
||||
{
|
||||
name: "a clearly different screen size adds a size",
|
||||
sizes: []config.SidePanelSize{{ScreenSize: 160, Ratio: 0.3125}},
|
||||
screenSize: 380,
|
||||
size: 80,
|
||||
expected: []config.SidePanelSize{
|
||||
{ScreenSize: 160, Ratio: 0.3125},
|
||||
{ScreenSize: 380, Ratio: 0.2105},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "a smaller screen size is sorted first",
|
||||
sizes: []config.SidePanelSize{{ScreenSize: 160, Ratio: 0.3125}},
|
||||
screenSize: 100,
|
||||
size: 40,
|
||||
expected: []config.SidePanelSize{
|
||||
{ScreenSize: 100, Ratio: 0.4},
|
||||
{ScreenSize: 160, Ratio: 0.3125},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "a similar screen size replaces the size",
|
||||
sizes: []config.SidePanelSize{
|
||||
{ScreenSize: 160, Ratio: 0.3125},
|
||||
{ScreenSize: 380, Ratio: 0.2105},
|
||||
},
|
||||
screenSize: 400,
|
||||
size: 100,
|
||||
expected: []config.SidePanelSize{
|
||||
{ScreenSize: 160, Ratio: 0.3125},
|
||||
{ScreenSize: 400, Ratio: 0.25},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "replaces all similar screen sizes",
|
||||
sizes: []config.SidePanelSize{
|
||||
{ScreenSize: 100, Ratio: 0.4},
|
||||
{ScreenSize: 110, Ratio: 0.35},
|
||||
{ScreenSize: 120, Ratio: 0.3},
|
||||
{ScreenSize: 200, Ratio: 0.2},
|
||||
},
|
||||
screenSize: 110,
|
||||
size: 33,
|
||||
expected: []config.SidePanelSize{
|
||||
{ScreenSize: 110, Ratio: 0.3},
|
||||
{ScreenSize: 200, Ratio: 0.2},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
assert.Equal(t, s.expected, recordSidePanelSize(s.sizes, s.screenSize, s.size))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordedSidePanelSizeComesBackUnchanged(t *testing.T) {
|
||||
for screenSize := 20; screenSize <= 2000; screenSize++ {
|
||||
for _, size := range []int{3, screenSize / 3, screenSize - 3} {
|
||||
sizes := recordSidePanelSize(nil, screenSize, size)
|
||||
result, ok := sidePanelSizeForScreen(sizes, screenSize)
|
||||
assert.True(t, ok)
|
||||
if result != size {
|
||||
t.Fatalf("size %d at screen size %d came back as %d", size, screenSize, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidSidePanelSizes(t *testing.T) {
|
||||
input := map[config.SidePanelLayout][]config.SidePanelSize{
|
||||
config.SidePanelLayoutNormal: {
|
||||
|
||||
@@ -89,6 +89,32 @@ func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string,
|
||||
return GetWindowDimensions(self.windowArrangementArgs(informationStr, appStatus))
|
||||
}
|
||||
|
||||
// SidePanelArrangement describes how the side panels and the main view share
|
||||
// the screen.
|
||||
type SidePanelArrangement struct {
|
||||
Layout config.SidePanelLayout
|
||||
// True if the side panels are above the main view, false if they are left
|
||||
// of it
|
||||
SidePanelsAbove bool
|
||||
// The size of the screen that config.SidePanelSize refers to
|
||||
ScreenSize int
|
||||
}
|
||||
|
||||
// GetSidePanelArrangement returns how the side panels and the main view share
|
||||
// the screen, or false if only one of the two is visible.
|
||||
func (self *WindowArrangementHelper) GetSidePanelArrangement(informationStr string, appStatus string) (SidePanelArrangement, bool) {
|
||||
args := self.windowArrangementArgs(informationStr, appStatus)
|
||||
layout, ok := sidePanelLayout(args)
|
||||
if !ok {
|
||||
return SidePanelArrangement{}, false
|
||||
}
|
||||
return SidePanelArrangement{
|
||||
Layout: layout,
|
||||
SidePanelsAbove: shouldUsePortraitMode(args),
|
||||
ScreenSize: sidePanelScreenSize(args),
|
||||
}, true
|
||||
}
|
||||
|
||||
func (self *WindowArrangementHelper) windowArrangementArgs(informationStr string, appStatus string) WindowArrangementArgs {
|
||||
width, height := self.c.GocuiGui().Size()
|
||||
repoState := self.c.State().GetRepoState()
|
||||
|
||||
@@ -210,6 +210,10 @@ func (self *StateAccessor) GetSidePanelSizes() map[config.SidePanelLayout][]conf
|
||||
return self.gui.SidePanelSizes
|
||||
}
|
||||
|
||||
func (self *StateAccessor) SetSidePanelSizes(value map[config.SidePanelLayout][]config.SidePanelSize) {
|
||||
self.gui.SidePanelSizes = value
|
||||
}
|
||||
|
||||
func (self *StateAccessor) GetRetainOriginalDir() bool {
|
||||
return self.gui.RetainOriginalDir
|
||||
}
|
||||
@@ -412,6 +416,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||
return reloadErr
|
||||
}
|
||||
|
||||
gui.helpers.SidePanelResize.OnFocusLost()
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -991,6 +996,13 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
gui.g.OnMouseMove = func(x, y int) {
|
||||
gui.helpers.SidePanelResize.OnMouseMove(x, y)
|
||||
}
|
||||
gui.g.InterceptMouse = func(ev gocui.MouseEvent) bool {
|
||||
return gui.helpers.SidePanelResize.InterceptMouse(ev)
|
||||
}
|
||||
|
||||
gui.g.ShouldHandleMouseEvent = func(view *gocui.View, key gocui.KeyName) bool {
|
||||
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != view.Name() &&
|
||||
!gocui.IsMouseScrollKey(key) {
|
||||
|
||||
@@ -223,6 +223,9 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||
// gui.c.Log.Info(utils.AsJson(gui.State.Model.Branches[0:4]))
|
||||
gui.helpers.Confirmation.ResizeCurrentPopupPanels()
|
||||
|
||||
sidePanelArrangement, hasSidePanelArrangement := gui.helpers.WindowArrangement.GetSidePanelArrangement(informationStr, appStatus)
|
||||
gui.helpers.SidePanelResize.Layout(viewDimensions, sidePanelArrangement, hasSidePanelArrangement)
|
||||
|
||||
gui.renderContextOptionsMap()
|
||||
|
||||
outer:
|
||||
|
||||
@@ -26,6 +26,10 @@ func (gui *Gui) renderContextOptionsMap() {
|
||||
return
|
||||
}
|
||||
mgr := OptionsMapMgr{c: gui.c}
|
||||
if gui.helpers.SidePanelResize.IsActive() {
|
||||
mgr.renderOptions(theme.OptionsFgColor.Sprint(gui.c.Tr.SidePanelResizeHint))
|
||||
return
|
||||
}
|
||||
mgr.renderContextOptionsMap()
|
||||
}
|
||||
|
||||
|
||||
@@ -442,6 +442,7 @@ type IStateAccessor interface {
|
||||
GetShowExtrasWindow() bool
|
||||
SetShowExtrasWindow(bool)
|
||||
GetSidePanelSizes() map[config.SidePanelLayout][]config.SidePanelSize
|
||||
SetSidePanelSizes(map[config.SidePanelLayout][]config.SidePanelSize)
|
||||
GetRetainOriginalDir() bool
|
||||
SetRetainOriginalDir(bool)
|
||||
GetItemOperation(item HasUrn) ItemOperation
|
||||
|
||||
@@ -861,6 +861,7 @@ type TranslationSet struct {
|
||||
CantSwitchWhileOperationInProgress string
|
||||
CommandLog string
|
||||
ToggleShowCommandLog string
|
||||
SidePanelResizeHint string
|
||||
FocusCommandLog string
|
||||
CommandLogHeader string
|
||||
RandomTip string
|
||||
@@ -2093,6 +2094,7 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
ErrWorktreeMovedOrRemoved: "Cannot find worktree. It might have been moved or removed ¯\\_(ツ)_/¯",
|
||||
CantSwitchWhileOperationInProgress: "Can't switch repositories while an operation is in progress",
|
||||
ToggleShowCommandLog: "Toggle show/hide command log",
|
||||
SidePanelResizeHint: "Drag to resize | Double-click to reset",
|
||||
FocusCommandLog: "Focus command log",
|
||||
CommandLogHeader: "You can hide/focus this panel by pressing '%s'\n",
|
||||
RandomTip: "Random tip",
|
||||
|
||||
@@ -741,6 +741,7 @@ var tests = []*components.IntegrationTest{
|
||||
ui.RangeSelectWithAutoscroll,
|
||||
ui.ReloadSidePanels,
|
||||
ui.ReorderSidePanels,
|
||||
ui.ResizeSidePanelsByDragging,
|
||||
ui.SubCommitsScrollPositionIsReset,
|
||||
ui.SuggestionsSelectionFollowsTheFocus,
|
||||
ui.SwitchRepoMovesTheSelection,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var ResizeSidePanelsByDragging = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Resize the side panels by dragging the boundary between them and the main view",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
Width: 120,
|
||||
Height: 30,
|
||||
SetupConfig: func(config *config.AppConfig) {},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.EmptyCommit("initial commit")
|
||||
shell.CreateFile("file", "content")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Files().
|
||||
IsFocused().
|
||||
HasWidth(40).
|
||||
// The right edge of the files panel is part of the boundary
|
||||
Hover(38, 1)
|
||||
|
||||
t.Views().Options().
|
||||
Content(Equals("Drag to resize | Double-click to reset"))
|
||||
|
||||
// The left edge of the main view is part of the boundary, too
|
||||
t.Views().Main().
|
||||
ClickAndHold(-1, 3).
|
||||
MouseMove(-21, 3).
|
||||
MouseRelease()
|
||||
|
||||
t.Views().Files().
|
||||
IsFocused().
|
||||
HasWidth(20)
|
||||
t.Views().Main().
|
||||
HasWidth(100)
|
||||
|
||||
t.Views().Main().
|
||||
Hover(10, 3)
|
||||
|
||||
t.Views().Options().
|
||||
Content(DoesNotContain("Drag to resize"))
|
||||
|
||||
// A click on the boundary doesn't focus the main view
|
||||
t.Views().Main().
|
||||
Click(-1, 3)
|
||||
|
||||
t.Views().Files().
|
||||
IsFocused().
|
||||
HasWidth(20)
|
||||
|
||||
t.Views().Main().
|
||||
DoubleClick(-1, 3)
|
||||
|
||||
t.Views().Files().
|
||||
HasWidth(40)
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user