mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Fixes #39: Todo crashes when space pressed with no selection
This commit is contained in:
parent
432669ab9b
commit
89b1b0f517
24
todo/list.go
24
todo/list.go
@ -24,6 +24,10 @@ func (list *List) Delete() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (list *List) Demote() {
|
func (list *List) Demote() {
|
||||||
|
if list.isUnselectable() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
j := list.selected + 1
|
j := list.selected + 1
|
||||||
if j >= len(list.Items) {
|
if j >= len(list.Items) {
|
||||||
j = 0
|
j = 0
|
||||||
@ -48,6 +52,10 @@ func (list *List) Prev() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (list *List) Promote() {
|
func (list *List) Promote() {
|
||||||
|
if list.isUnselectable() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
j := list.selected - 1
|
j := list.selected - 1
|
||||||
if j < 0 {
|
if j < 0 {
|
||||||
j = len(list.Items) - 1
|
j = len(list.Items) - 1
|
||||||
@ -58,7 +66,7 @@ func (list *List) Promote() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (list *List) Selected() *Item {
|
func (list *List) Selected() *Item {
|
||||||
if list.selected < 0 || list.selected >= len(list.Items) {
|
if list.isUnselectable() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +75,10 @@ func (list *List) Selected() *Item {
|
|||||||
|
|
||||||
// Toggle switches the checked state of the selected item
|
// Toggle switches the checked state of the selected item
|
||||||
func (list *List) Toggle() {
|
func (list *List) Toggle() {
|
||||||
|
if list.isUnselectable() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
list.Items[list.selected].Toggle()
|
list.Items[list.selected].Toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,3 +109,13 @@ func (list *List) Less(i, j int) bool {
|
|||||||
func (list *List) Swap(i, j int) {
|
func (list *List) Swap(i, j int) {
|
||||||
list.Items[i], list.Items[j] = list.Items[j], list.Items[i]
|
list.Items[i], list.Items[j] = list.Items[j], list.Items[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (list *List) isSelectable() bool {
|
||||||
|
return list.selected >= 0 && list.selected < len(list.Items)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (list *List) isUnselectable() bool {
|
||||||
|
return !list.isSelectable()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user