correct bounds checks on views
This commit is contained in:
3 files changed
+11
-6
No files matched your search
+7
-3
@@ -116,6 +116,8 @@ func (view *FileTreeView) setLayer(layerIndex int) error {
|
||||
}
|
||||
|
||||
func (view *FileTreeView) CursorDown() error {
|
||||
// cannot easily (quickly) check the model length, allow the view
|
||||
// to let us know what is a valid bounds (i.e. when it hits an empty line)
|
||||
err := CursorDown(view.gui, view.view)
|
||||
if err == nil {
|
||||
view.TreeIndex++
|
||||
@@ -124,9 +126,11 @@ func (view *FileTreeView) CursorDown() error {
|
||||
}
|
||||
|
||||
func (view *FileTreeView) CursorUp() error {
|
||||
err := CursorUp(view.gui, view.view)
|
||||
if err == nil {
|
||||
view.TreeIndex--
|
||||
if view.TreeIndex > 0 {
|
||||
err := CursorUp(view.gui, view.view)
|
||||
if err == nil {
|
||||
view.TreeIndex--
|
||||
}
|
||||
}
|
||||
return view.Render()
|
||||
}
|
||||
|
||||
+2
-2
@@ -79,7 +79,7 @@ func (view *LayerView) Render() error {
|
||||
}
|
||||
|
||||
func (view *LayerView) CursorDown() error {
|
||||
if int(view.LayerIndex) < len(view.Layers) {
|
||||
if view.LayerIndex < len(view.Layers) {
|
||||
err := CursorDown(view.gui, view.view)
|
||||
if err == nil {
|
||||
view.LayerIndex++
|
||||
@@ -91,7 +91,7 @@ func (view *LayerView) CursorDown() error {
|
||||
}
|
||||
|
||||
func (view *LayerView) CursorUp() error {
|
||||
if int(view.LayerIndex) > 0 {
|
||||
if view.LayerIndex > 0 {
|
||||
err := CursorUp(view.gui, view.view)
|
||||
if err == nil {
|
||||
view.LayerIndex--
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/wagoodman/docker-image-explorer/filetree"
|
||||
"github.com/wagoodman/docker-image-explorer/image"
|
||||
"github.com/fatih/color"
|
||||
"github.com/wagoodman/docker-image-explorer/_vendor-20180604210951/github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const debug = false
|
||||
@@ -51,7 +52,7 @@ func CursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
// todo: handle error
|
||||
}
|
||||
if len(line) == 0 {
|
||||
return nil
|
||||
return errors.New("unable to move cursor down, empty line")
|
||||
}
|
||||
if err := v.SetCursor(cx, cy+1); err != nil {
|
||||
ox, oy := v.Origin()
|
||||
|
||||
Reference in new issue
Block a user