From 34dcdbbe66212492cc32f8a14a16ff5f255431e3 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 23 Apr 2018 17:05:37 -0700 Subject: [PATCH] Better keyboard support for todo --- todo/item.go | 1 - todo/list.go | 1 - todo/widget.go | 28 ++++++++++++++++++++-------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/todo/item.go b/todo/item.go index 172b95d0..aa77f41e 100644 --- a/todo/item.go +++ b/todo/item.go @@ -4,7 +4,6 @@ import () type Item struct { Checked bool - Index int Text string } diff --git a/todo/list.go b/todo/list.go index 097305c1..ff94aa33 100644 --- a/todo/list.go +++ b/todo/list.go @@ -11,7 +11,6 @@ type List struct { } func (list *List) Delete() { - fmt.Println("del") list.Items = append(list.Items[:list.selected], list.Items[list.selected+1:]...) } diff --git a/todo/widget.go b/todo/widget.go index a4ab4c42..171f28ce 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -67,30 +67,42 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { case "e": // Edit selected item 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": // Add a new item return nil } switch event.Key() { - case tcell.KeyCtrlA: - // Move the selected item up - widget.list.Promote() - widget.persist() - widget.display() - return nil case tcell.KeyCtrlD: // Delete the selected item widget.list.Delete() widget.persist() widget.display() return nil - case tcell.KeyCtrlZ: - // Move the selected item down + case tcell.KeyCtrlJ: + // Move selected item down in the list widget.list.Demote() widget.persist() widget.display() return nil + case tcell.KeyCtrlK: + // Move selected item up in the list + widget.list.Promote() + widget.persist() + widget.display() + return nil case tcell.KeyDown: // Select the next item down widget.list.Next()