Skip to content

Commit

Permalink
feat: allow moving a task to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jul 23, 2024
1 parent 841d078 commit 3b38b47
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/assets/guide/domain-task-priorities.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tasks on any given day. As such, omm allows you to move tasks around in the
priority order. It has the following keymaps to achieve this:

⏎ move task to the top
E move task to the end
J move task one position down
K move task one position up

Expand Down
1 change: 1 addition & 0 deletions internal/ui/assets/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ omm has 6 components:
A add task at the end
u update task summary
⏎ move task to the top
E move task to the end
J move task one position down
K move task one position up

Expand Down
47 changes: 45 additions & 2 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

var index int
if m.taskList.IsFiltered() {
m.errorMsg = "Cannot move items when the task list is filtered"
selected, ok := m.taskList.SelectedItem().(types.Task)
if !ok {
break
Expand All @@ -638,7 +637,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !ok {
m.errorMsg = "Something went wrong; cannot move item to the top"
}

index = listIndex
} else {
index = m.taskList.Index()
Expand Down Expand Up @@ -709,6 +707,51 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Sequence(cmds...)
}

case "E":
if m.activeView != taskListView {
break
}

if len(m.taskList.Items()) == 0 {
break
}

var index int
if m.taskList.IsFiltered() {
selected, ok := m.taskList.SelectedItem().(types.Task)
if !ok {
break
}
listIndex, ok := m.tlIndexMap[selected.ID]
if !ok {
m.errorMsg = "Something went wrong; cannot move item to the end"
}
index = listIndex
} else {
index = m.taskList.Index()
}

lastIndex := len(m.taskList.Items()) - 1

if index == lastIndex {
m.errorMsg = "This item is already at the end of the list"
break
}

if m.taskList.IsFiltered() {
m.taskList.ResetFilter()
m.taskList.Select(index)
}

listItem := m.taskList.SelectedItem()
m.taskList.RemoveItem(index)
cmd = m.taskList.InsertItem(lastIndex, listItem)
cmds = append(cmds, cmd)
m.taskList.Select(lastIndex)

cmd = m.updateTaskSequence()
cmds = append(cmds, cmd)

case "c":
if m.activeView != taskListView && m.activeView != archivedTaskListView && m.activeView != taskDetailsView {
break
Expand Down

0 comments on commit 3b38b47

Please sign in to comment.