[WIP] Editing

This commit is contained in:
Martin Pander
2024-05-23 16:01:25 +02:00
parent 7712711736
commit fe00170a5c
6 changed files with 133 additions and 24 deletions

View File

@ -150,6 +150,9 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
p.subpageActive = true
p.common.PushPage(p)
return p.subpage, nil
case key.Matches(msg, p.common.Keymap.Undo):
p.common.TW.Undo()
return p, p.getTasks()
}
}
@ -175,6 +178,8 @@ func (p *ReportPage) View() string {
}
func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
var selected int
nCols := len(p.activeReport.Columns)
columns := make([]table.Column, 0)
columnSizes := make([]int, nCols)
@ -182,6 +187,10 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
rows := make([]table.Row, len(tasks))
for i, task := range tasks {
if p.selectedTask != nil && task.Uuid == p.selectedTask.Uuid {
selected = i
}
row := table.Row{}
for i, col := range p.activeReport.Columns {
field := task.GetString(col)
@ -210,6 +219,10 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
columns = append(columns, table.Column{Title: label, Width: max(columnSizes[i], len(label))})
}
if selected == 0 {
selected = p.taskTable.Cursor()
}
p.taskTable = table.New(
table.WithColumns(columns),
table.WithRows(rows),
@ -218,6 +231,12 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
// table.WithWidth(100),
)
p.taskTable.SetStyles(p.tableStyle)
if selected < len(p.tasks) {
p.taskTable.SetCursor(selected)
} else {
p.taskTable.SetCursor(len(p.tasks) - 1)
}
}
func (p *ReportPage) getTasks() tea.Cmd {