mirror of
https://github.com/jroimartin/gocui.git
synced 2025-04-30 13:48:54 +08:00
handle out of bounds errors
This commit is contained in:
parent
1b445b9bd5
commit
53875d55c3
11
view.go
11
view.go
@ -153,10 +153,18 @@ func (v *View) gotoPreviousMatch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *View) SelectSearchResult(index int) error {
|
func (v *View) SelectSearchResult(index int) error {
|
||||||
|
itemCount := len(v.searcher.searchPositions)
|
||||||
|
if itemCount == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if index > itemCount-1 {
|
||||||
|
index = itemCount - 1
|
||||||
|
}
|
||||||
|
|
||||||
y := v.searcher.searchPositions[index].y
|
y := v.searcher.searchPositions[index].y
|
||||||
v.FocusPoint(0, y)
|
v.FocusPoint(0, y)
|
||||||
if v.searcher.onSelectItem != nil {
|
if v.searcher.onSelectItem != nil {
|
||||||
return v.searcher.onSelectItem(y, index, len(v.searcher.searchPositions))
|
return v.searcher.onSelectItem(y, index, itemCount)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -183,7 +191,6 @@ func (v *View) Search(str string) error {
|
|||||||
} else {
|
} else {
|
||||||
return v.searcher.onSelectItem(-1, -1, 0)
|
return v.searcher.onSelectItem(-1, -1, 0)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *View) ClearSearch() {
|
func (v *View) ClearSearch() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user