mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Can promote/demote todo list items
This commit is contained in:
parent
4fb308c555
commit
db162feddd
20
todo/list.go
20
todo/list.go
@ -13,6 +13,16 @@ func (list *List) Delete() {
|
||||
list.Items = append(list.Items[:list.selected], list.Items[list.selected+1:]...)
|
||||
}
|
||||
|
||||
func (list *List) Demote() {
|
||||
j := list.selected + 1
|
||||
if j >= len(list.Items) {
|
||||
j = 0
|
||||
}
|
||||
|
||||
list.Swap(list.selected, j)
|
||||
list.selected = j
|
||||
}
|
||||
|
||||
func (list *List) Next() {
|
||||
list.selected = list.selected + 1
|
||||
if list.selected >= len(list.Items) {
|
||||
@ -27,6 +37,16 @@ func (list *List) Prev() {
|
||||
}
|
||||
}
|
||||
|
||||
func (list *List) Promote() {
|
||||
j := list.selected - 1
|
||||
if j < 0 {
|
||||
j = len(list.Items) - 1
|
||||
}
|
||||
|
||||
list.Swap(list.selected, j)
|
||||
list.selected = j
|
||||
}
|
||||
|
||||
// Toggle switches the checked state of the selected item
|
||||
func (list *List) Toggle() {
|
||||
list.Items[list.selected].Toggle()
|
||||
|
@ -73,19 +73,31 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyCtrlA:
|
||||
// Move the selected item up
|
||||
widget.list.Promote()
|
||||
widget.persist()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyCtrlD:
|
||||
// Delete selected item
|
||||
// Delete the selected item
|
||||
widget.list.Delete()
|
||||
widget.persist()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyCtrlZ:
|
||||
// Move the selected item down
|
||||
widget.list.Demote()
|
||||
widget.persist()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyDown:
|
||||
// Select the next item down
|
||||
widget.list.Next()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
// Unselect the current row (pass it on)
|
||||
// Unselect the current row
|
||||
widget.list.Unselect()
|
||||
widget.display()
|
||||
return event
|
||||
|
Loading…
x
Reference in New Issue
Block a user