Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions column.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ func (c column) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, keys.Delete):
return c, c.DeleteCurrent()
case key.Matches(msg, keys.Enter):
return c, c.MoveToNext()
return c, c.Move("next")
case key.Matches(msg, keys.ItemRight):
return c, c.Move("next")
case key.Matches(msg, keys.ItemLeft):
return c, c.Move("prev")
}

}
c.list, cmd = c.list.Update(msg)
return c, cmd
Expand Down Expand Up @@ -119,9 +124,10 @@ func (c *column) getStyle() lipgloss.Style {

type moveMsg struct {
Task
direction string
}

func (c *column) MoveToNext() tea.Cmd {
func (c *column) Move(direction string) tea.Cmd {
var task Task
var ok bool
// If nothing is selected, the SelectedItem will return Nil.
Expand All @@ -130,11 +136,17 @@ func (c *column) MoveToNext() tea.Cmd {
}
// move item
c.list.RemoveItem(c.list.Index())
task.status = c.status.getNext()

switch direction {
case "prev":
task.status = c.status.getPrev()
case "next":
task.status = c.status.getNext()
}

// refresh list
var cmd tea.Cmd
c.list, cmd = c.list.Update(nil)

return tea.Sequence(cmd, func() tea.Msg { return moveMsg{task} })
return tea.Sequence(cmd, func() tea.Msg { return moveMsg{task, direction} })
}
35 changes: 23 additions & 12 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ func (k keyMap) ShortHelp() []key.Binding {
func (k keyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Left, k.Right}, // first column
{k.Help, k.Quit}, // second column
{k.ItemLeft, k.ItemRight}, // second column
{k.Help, k.Quit}, // third column
}
}

type keyMap struct {
New key.Binding
Edit key.Binding
Delete key.Binding
Up key.Binding
Down key.Binding
Right key.Binding
Left key.Binding
Enter key.Binding
Help key.Binding
Quit key.Binding
Back key.Binding
New key.Binding
Edit key.Binding
Delete key.Binding
Up key.Binding
Down key.Binding
Right key.Binding
Left key.Binding
Enter key.Binding
Help key.Binding
Quit key.Binding
Back key.Binding
ItemLeft key.Binding
ItemRight key.Binding
}

var keys = keyMap{
Expand Down Expand Up @@ -64,6 +67,14 @@ var keys = keyMap{
key.WithKeys("enter"),
key.WithHelp("enter", "enter"),
),
ItemLeft: key.NewBinding(
key.WithKeys("ctrl+left", "ctrl+h"),
key.WithHelp("ctrl+←/ctrl+h", "move item left"),
),
ItemRight: key.NewBinding(
key.WithKeys("ctrl+right", "ctrl+l"),
key.WithHelp("ctrl+→/ctrl+l", "move item right"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
Expand Down
7 changes: 6 additions & 1 deletion model.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ func (m *Board) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case Form:
return m, m.cols[m.focused].Set(msg.index, msg.CreateTask())
case moveMsg:
return m, m.cols[m.focused.getNext()].Set(APPEND, msg.Task)
switch msg.direction {
case "prev":
return m, m.cols[m.focused.getPrev()].Set(APPEND, msg.Task)
case "next":
return m, m.cols[m.focused.getNext()].Set(APPEND, msg.Task)
}
case tea.KeyMsg:
switch {
case key.Matches(msg, keys.Quit):
Expand Down