mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
fixup layout origin/cursor changing
This commit is contained in:
parent
55894b4a5e
commit
1bf9c47438
3 changed files with 44 additions and 18 deletions
|
|
@ -267,9 +267,10 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
|
|
||||||
// TODO: find out if I should add the services view to this.
|
// TODO: find out if I should add the services view to this.
|
||||||
listViews := map[*gocui.View]listViewState{
|
listViews := map[*gocui.View]listViewState{
|
||||||
containersView: {selectedLine: gui.State.Panels.Containers.SelectedLine, lineCount: len(gui.DockerCommand.Containers)},
|
containersView: {selectedLine: gui.State.Panels.Containers.SelectedLine, lineCount: len(gui.DockerCommand.DisplayContainers)},
|
||||||
imagesView: {selectedLine: gui.State.Panels.Images.SelectedLine, lineCount: len(gui.DockerCommand.Images)},
|
imagesView: {selectedLine: gui.State.Panels.Images.SelectedLine, lineCount: len(gui.DockerCommand.Images)},
|
||||||
volumesView: {selectedLine: gui.State.Panels.Volumes.SelectedLine, lineCount: len(gui.DockerCommand.Volumes)},
|
volumesView: {selectedLine: gui.State.Panels.Volumes.SelectedLine, lineCount: len(gui.DockerCommand.Volumes)},
|
||||||
|
servicesView: {selectedLine: gui.State.Panels.Services.SelectedLine, lineCount: len(gui.DockerCommand.Services)},
|
||||||
}
|
}
|
||||||
|
|
||||||
// menu view might not exist so we check to be safe
|
// menu view might not exist so we check to be safe
|
||||||
|
|
|
||||||
|
|
@ -146,32 +146,49 @@ func (gui *Gui) resetOrigin(v *gocui.View) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the cursor down past the last item, move it to the last line
|
// if the cursor down past the last item, move it to the last line
|
||||||
func (gui *Gui) focusPoint(cx int, cy int, lineCount int, v *gocui.View) error {
|
func (gui *Gui) focusPoint(selectedX int, selectedY int, lineCount int, v *gocui.View) error {
|
||||||
if cy < 0 || cy > lineCount {
|
if selectedY < 0 || selectedY > lineCount {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ox, oy := v.Origin()
|
ox, oy := v.Origin()
|
||||||
|
originalOy := oy
|
||||||
|
cx, cy := v.Cursor()
|
||||||
|
originalCy := cy
|
||||||
_, height := v.Size()
|
_, height := v.Size()
|
||||||
|
|
||||||
ly := height - 1
|
ly := utils.Max(height-1, 0)
|
||||||
if ly == -1 {
|
|
||||||
ly = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// if line is above origin, move origin and set cursor to zero
|
// if line is above origin, move origin and set cursor to zero
|
||||||
// if line is below origin + height, move origin and set cursor to max
|
// if line is below origin + height, move origin and set cursor to max
|
||||||
// otherwise set cursor to value - origin
|
// otherwise set cursor to value - origin
|
||||||
if ly > lineCount {
|
gui.Log.Warn("ly: ", ly)
|
||||||
_ = v.SetCursor(cx, cy)
|
gui.Log.Warn("lineCount: ", lineCount)
|
||||||
_ = v.SetOrigin(ox, 0)
|
gui.Log.Warn("selectedY: ", selectedY)
|
||||||
} else if cy < oy {
|
gui.Log.Warn("oy: ", oy)
|
||||||
_ = v.SetCursor(cx, 0)
|
gui.Log.Warn("cy: ", cy)
|
||||||
_ = v.SetOrigin(ox, cy)
|
|
||||||
} else if cy > oy+ly {
|
windowStart := oy
|
||||||
_ = v.SetCursor(cx, ly)
|
windowEnd := oy + ly
|
||||||
_ = v.SetOrigin(ox, cy-ly)
|
|
||||||
} else {
|
if selectedY < windowStart {
|
||||||
_ = v.SetCursor(cx, cy-oy)
|
gui.Log.Warn("one")
|
||||||
|
oy = utils.Max(oy-(windowStart-selectedY), 0)
|
||||||
|
} else if selectedY > windowEnd {
|
||||||
|
gui.Log.Warn("two")
|
||||||
|
oy += (selectedY - windowEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
if windowEnd > lineCount-1 {
|
||||||
|
gui.Log.Warn("three")
|
||||||
|
shiftAmount := (windowEnd - (lineCount - 1))
|
||||||
|
oy = utils.Max(oy-shiftAmount, 0)
|
||||||
|
}
|
||||||
|
if originalOy != oy {
|
||||||
|
_ = v.SetOrigin(ox, oy)
|
||||||
|
}
|
||||||
|
cy = selectedY - oy
|
||||||
|
if originalCy != cy {
|
||||||
|
_ = v.SetCursor(cx, selectedY-oy)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,14 @@ func Min(x, y int) int {
|
||||||
return y
|
return y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Max returns the maximum of two integers
|
||||||
|
func Max(x, y int) int {
|
||||||
|
if x > y {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
|
||||||
type Displayable interface {
|
type Displayable interface {
|
||||||
GetDisplayStrings(bool) []string
|
GetDisplayStrings(bool) []string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue