Add things

This commit is contained in:
Martin Pander
2026-02-10 15:54:08 +01:00
parent e35f480248
commit 703ed981ac
13 changed files with 901 additions and 50 deletions

View File

@@ -159,6 +159,40 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmd := p.subpage.Init()
p.common.PushPage(p)
return p.subpage, cmd
case key.Matches(msg, p.common.Keymap.Subtask):
if p.selectedTask != nil {
// Create new task inheriting parent's attributes
newTask := taskwarrior.NewTask()
// Set parent relationship
newTask.Parent = p.selectedTask.Uuid
// Copy parent's attributes
newTask.Project = p.selectedTask.Project
newTask.Priority = p.selectedTask.Priority
newTask.Tags = make([]string, len(p.selectedTask.Tags))
copy(newTask.Tags, p.selectedTask.Tags)
// Copy UDAs (except "details" which is task-specific)
if p.selectedTask.Udas != nil {
newTask.Udas = make(map[string]any)
for k, v := range p.selectedTask.Udas {
// Skip "details" UDA - it's specific to parent task
if k == "details" {
continue
}
// Deep copy other UDA values
newTask.Udas[k] = v
}
}
// Open task editor with pre-populated task
p.subpage = NewTaskEditorPage(p.common, newTask)
cmd := p.subpage.Init()
p.common.PushPage(p)
return p.subpage, cmd
}
return p, nil
case key.Matches(msg, p.common.Keymap.Ok):
p.common.TW.SetTaskDone(p.selectedTask)
return p, p.getTasks()
@@ -264,17 +298,28 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
return
}
// Build task tree for hierarchical display
taskTree := taskwarrior.BuildTaskTree(tasks)
// Use flattened tree list for display order
orderedTasks := make(taskwarrior.Tasks, len(taskTree.FlatList))
for i, node := range taskTree.FlatList {
orderedTasks[i] = node.Task
}
selected := p.taskTable.Cursor()
// Adjust cursor for tree ordering
if p.selectedTask != nil {
for i, task := range tasks {
for i, task := range orderedTasks {
if task.Uuid == p.selectedTask.Uuid {
selected = i
break
}
}
}
if selected > len(tasks)-1 {
selected = len(tasks) - 1
if selected > len(orderedTasks)-1 {
selected = len(orderedTasks) - 1
}
// Calculate proper dimensions based on whether details panel is active
@@ -294,7 +339,8 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
p.taskTable = table.New(
p.common,
table.WithReport(p.activeReport),
table.WithTasks(tasks),
table.WithTasks(orderedTasks),
table.WithTaskTree(taskTree),
table.WithFocused(true),
table.WithWidth(baseWidth),
table.WithHeight(tableHeight),
@@ -304,7 +350,7 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
if selected == 0 {
selected = p.taskTable.Cursor()
}
if selected < len(tasks) {
if selected < len(orderedTasks) {
p.taskTable.SetCursor(selected)
} else {
p.taskTable.SetCursor(len(p.tasks) - 1)