mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Better keyboard support for todo
This commit is contained in:
parent
a92af549fe
commit
34dcdbbe66
@ -4,7 +4,6 @@ import ()
|
|||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Checked bool
|
Checked bool
|
||||||
Index int
|
|
||||||
Text string
|
Text string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ type List struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (list *List) Delete() {
|
func (list *List) Delete() {
|
||||||
fmt.Println("del")
|
|
||||||
list.Items = append(list.Items[:list.selected], list.Items[list.selected+1:]...)
|
list.Items = append(list.Items[:list.selected], list.Items[list.selected+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,30 +67,42 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
case "e":
|
case "e":
|
||||||
// Edit selected item
|
// Edit selected item
|
||||||
return nil
|
return nil
|
||||||
|
case "h":
|
||||||
|
// Show help menu
|
||||||
|
fmt.Println("HELP!")
|
||||||
|
return nil
|
||||||
|
case "j":
|
||||||
|
widget.list.Next()
|
||||||
|
widget.display()
|
||||||
|
return nil
|
||||||
|
case "k":
|
||||||
|
widget.list.Prev()
|
||||||
|
widget.display()
|
||||||
|
return nil
|
||||||
case "n":
|
case "n":
|
||||||
// Add a new item
|
// Add a new item
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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 the 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:
|
case tcell.KeyCtrlJ:
|
||||||
// Move the selected item down
|
// Move selected item down in the list
|
||||||
widget.list.Demote()
|
widget.list.Demote()
|
||||||
widget.persist()
|
widget.persist()
|
||||||
widget.display()
|
widget.display()
|
||||||
return nil
|
return nil
|
||||||
|
case tcell.KeyCtrlK:
|
||||||
|
// Move selected item up in the list
|
||||||
|
widget.list.Promote()
|
||||||
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user