1
0
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:
Chris Cummer 2018-04-22 21:56:36 -07:00
parent 4fb308c555
commit db162feddd
2 changed files with 34 additions and 2 deletions

View File

@ -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()

View File

@ -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