fix: improve keyboard capture events

This commit is contained in:
Dan Anglin 2023-04-23 04:27:16 +01:00
parent b16fe8eb60
commit 283da856ff
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 19 additions and 16 deletions

View file

@ -45,7 +45,6 @@ func Open(path string) (Board, error) {
} }
} }
return board, nil return board, nil
} }
@ -106,7 +105,7 @@ func (b *Board) DeleteStatus() error {
} }
type CardArgs struct { type CardArgs struct {
NewTitle string NewTitle string
NewContent string NewContent string
} }
@ -218,7 +217,7 @@ func (b *Board) UpdateCard(args UpdateCardArgs) error {
} }
type UpdateCardStatusArgs struct { type UpdateCardStatusArgs struct {
CardID int CardID int
OldStatusID int OldStatusID int
NewStatusID int NewStatusID int
} }

View file

@ -51,7 +51,7 @@ func testCreateCard(t *testing.T, b board.Board, title, content string, wantID i
t.Helper() t.Helper()
args := board.CardArgs{ args := board.CardArgs{
NewTitle: title, NewTitle: title,
NewContent: content, NewContent: content,
} }
@ -108,7 +108,7 @@ func testUpdateCard(t *testing.T, b board.Board, cardID int, newTitle, newConten
args := board.UpdateCardArgs{ args := board.UpdateCardArgs{
CardID: cardID, CardID: cardID,
CardArgs: board.CardArgs{ CardArgs: board.CardArgs{
NewTitle: newTitle, NewTitle: newTitle,
NewContent: newContent, NewContent: newContent,
}, },
} }
@ -141,7 +141,7 @@ func testUpdateCardContent(t *testing.T, b board.Board, cardID int, expectedTitl
args := board.UpdateCardArgs{ args := board.UpdateCardArgs{
CardID: cardID, CardID: cardID,
CardArgs: board.CardArgs{ CardArgs: board.CardArgs{
NewTitle: "", NewTitle: "",
NewContent: newContent, NewContent: newContent,
}, },
} }

View file

@ -22,9 +22,16 @@ func (u *UI) newColumn(statusID int, statusName string) column {
cards.SetWrapAround(false) cards.SetWrapAround(false)
cards.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { cards.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Rune() == 'h' || event.Key() == tcell.KeyLeft { switch event.Rune() {
case 'q':
u.pages.ShowPage(quitPageName)
u.SetFocus(u.quit)
case 'a':
u.pages.ShowPage(addPageName)
u.SetFocus(u.add)
case 'h':
u.shiftColumnFocus(shiftLeft) u.shiftColumnFocus(shiftLeft)
} else if event.Rune() == 'l' || event.Key() == tcell.KeyRight { case 'l':
u.shiftColumnFocus(shiftRight) u.shiftColumnFocus(shiftRight)
} }

View file

@ -65,14 +65,11 @@ func (u *UI) init() {
u.pages.AddPage(addPageName, u.add, false, false) u.pages.AddPage(addPageName, u.add, false, false)
u.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { u.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Rune() == 'q' { switch event.Rune() {
u.pages.ShowPage(quitPageName) case 'o':
u.SetFocus(u.quit) if u.flex.HasFocus() && len(u.columns) == 0 {
} else if event.Rune() == 'o' { u.openBoard("")
u.openBoard("") }
} else if event.Rune() == 'a' {
u.pages.ShowPage(addPageName)
u.SetFocus(u.add)
} }
return event return event