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:]...)
|
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() {
|
func (list *List) Next() {
|
||||||
list.selected = list.selected + 1
|
list.selected = list.selected + 1
|
||||||
if list.selected >= len(list.Items) {
|
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
|
// Toggle switches the checked state of the selected item
|
||||||
func (list *List) Toggle() {
|
func (list *List) Toggle() {
|
||||||
list.Items[list.selected].Toggle()
|
list.Items[list.selected].Toggle()
|
||||||
|
@ -73,19 +73,31 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
|
case tcell.KeyCtrlA:
|
||||||
|
// Move the selected item up
|
||||||
|
widget.list.Promote()
|
||||||
|
widget.persist()
|
||||||
|
widget.display()
|
||||||
|
return nil
|
||||||
case tcell.KeyCtrlD:
|
case tcell.KeyCtrlD:
|
||||||
// Delete selected item
|
// Delete the selected item
|
||||||
widget.list.Delete()
|
widget.list.Delete()
|
||||||
widget.persist()
|
widget.persist()
|
||||||
widget.display()
|
widget.display()
|
||||||
return nil
|
return nil
|
||||||
|
case tcell.KeyCtrlZ:
|
||||||
|
// Move the selected item down
|
||||||
|
widget.list.Demote()
|
||||||
|
widget.persist()
|
||||||
|
widget.display()
|
||||||
|
return nil
|
||||||
case tcell.KeyDown:
|
case tcell.KeyDown:
|
||||||
// Select the next item down
|
// Select the next item down
|
||||||
widget.list.Next()
|
widget.list.Next()
|
||||||
widget.display()
|
widget.display()
|
||||||
return nil
|
return nil
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
// Unselect the current row (pass it on)
|
// Unselect the current row
|
||||||
widget.list.Unselect()
|
widget.list.Unselect()
|
||||||
widget.display()
|
widget.display()
|
||||||
return event
|
return event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user