From 3b38b4759d45826a1466f7c13676d165ca59386f Mon Sep 17 00:00:00 2001 From: Dhruv Thakur Date: Tue, 23 Jul 2024 20:09:26 +0200 Subject: [PATCH] feat: allow moving a task to the end --- cmd/assets/guide/domain-task-priorities.md | 1 + internal/ui/assets/help.md | 1 + internal/ui/update.go | 47 +++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/cmd/assets/guide/domain-task-priorities.md b/cmd/assets/guide/domain-task-priorities.md index 21e26ff..ba5799d 100644 --- a/cmd/assets/guide/domain-task-priorities.md +++ b/cmd/assets/guide/domain-task-priorities.md @@ -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 diff --git a/internal/ui/assets/help.md b/internal/ui/assets/help.md index 4c75677..f1e6ef9 100644 --- a/internal/ui/assets/help.md +++ b/internal/ui/assets/help.md @@ -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 diff --git a/internal/ui/update.go b/internal/ui/update.go index d245cbf..92f2902 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -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 @@ -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() @@ -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