summaryrefslogtreecommitdiffstats
path: root/pkg/utils
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-10-30 20:23:25 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-05 19:22:01 +1100
commit820f3d5cbb556f1c117906e4174f35ecf71e2ed5 (patch)
tree591c593fff6636707d06860cc7b918a92c573de0 /pkg/utils
parent081598d98944cdb95bfa649812565127c0592f5e (diff)
support split view in staging panel and staging ranges
Diffstat (limited to 'pkg/utils')
-rw-r--r--pkg/utils/utils.go6
-rw-r--r--pkg/utils/utils_test.go8
2 files changed, 7 insertions, 7 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 3350e2d53..42470df88 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -233,18 +233,18 @@ func NextIndex(numbers []int, currentNumber int) int {
return index
}
}
- return 0
+ return len(numbers) - 1
}
// PrevIndex returns the index that comes before the given number, cycling if we reach the end
func PrevIndex(numbers []int, currentNumber int) int {
end := len(numbers) - 1
- for i := end; i >= 0; i -= 1 {
+ for i := end; i >= 0; i-- {
if numbers[i] < currentNumber {
return i
}
}
- return end
+ return 0
}
func AsJson(i interface{}) string {
diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go
index ed131aaca..704a7c56f 100644
--- a/pkg/utils/utils_test.go
+++ b/pkg/utils/utils_test.go
@@ -485,7 +485,7 @@ func TestNextIndex(t *testing.T) {
"no elements",
[]int{},
1,
- 0,
+ -1,
},
{
"one element",
@@ -503,7 +503,7 @@ func TestNextIndex(t *testing.T) {
"two elements, giving second one",
[]int{1, 2},
2,
- 0,
+ 1,
},
{
"three elements, giving second one",
@@ -534,7 +534,7 @@ func TestPrevIndex(t *testing.T) {
"no elements",
[]int{},
1,
- -1,
+ 0,
},
{
"one element",
@@ -546,7 +546,7 @@ func TestPrevIndex(t *testing.T) {
"two elements",
[]int{1, 2},
1,
- 1,
+ 0,
},
{
"three elements, giving second one",