summaryrefslogtreecommitdiff
path: root/internal/ui/table.go
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-22 14:16:15 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-22 14:16:15 +0300
commite42bb79ed74cb975db0c4b8128b9014f0f6acf33 (patch)
tree87e9e3e45325d1a0758e1b1a3088fac17ec1740b /internal/ui/table.go
parent74fc699fabd50e3072d81242a9ade62ef8af34bf (diff)
Add task creation hotkey
Diffstat (limited to 'internal/ui/table.go')
-rw-r--r--internal/ui/table.go61
1 files changed, 60 insertions, 1 deletions
diff --git a/internal/ui/table.go b/internal/ui/table.go
index a5c3e8e..482d89e 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -61,6 +61,9 @@ type Model struct {
filterEditing bool
filterInput textinput.Model
+ addingTask bool
+ addInput textinput.Model
+
searching bool
searchInput textinput.Model
searchRegex *regexp.Regexp
@@ -161,6 +164,9 @@ func New(filters []string) (Model, error) {
m.filterInput = textinput.New()
m.filterInput.Prompt = "filter: "
+ m.addInput = textinput.New()
+ m.addInput.Prompt = "add: "
+
m.defaultTheme = DefaultTheme()
m.theme = m.defaultTheme
@@ -471,6 +477,46 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.filterInput, cmd = m.filterInput.Update(msg)
return m, cmd
}
+ if m.addingTask {
+ switch msg.Type {
+ case tea.KeyEnter:
+ oldIDs := make(map[int]struct{})
+ for _, tsk := range m.tasks {
+ oldIDs[tsk.ID] = struct{}{}
+ }
+ task.Add(m.addInput.Value(), nil)
+ m.addingTask = false
+ m.addInput.Blur()
+ m.reload()
+ var newID int
+ row := -1
+ for i, tsk := range m.tasks {
+ if _, ok := oldIDs[tsk.ID]; !ok {
+ newID = tsk.ID
+ row = i
+ break
+ }
+ }
+ m.updateTableHeight()
+ if row >= 0 {
+ prevRow := m.tbl.Cursor()
+ prevCol := m.tbl.ColumnCursor()
+ m.tbl.SetCursor(row)
+ m.tbl.SetColumnCursor(7)
+ m.updateSelectionHighlight(prevRow, m.tbl.Cursor(), prevCol, m.tbl.ColumnCursor())
+ return m, m.startBlink(newID, false)
+ }
+ return m, nil
+ case tea.KeyEsc:
+ m.addingTask = false
+ m.addInput.Blur()
+ m.updateTableHeight()
+ return m, nil
+ }
+ var cmd tea.Cmd
+ m.addInput, cmd = m.addInput.Update(msg)
+ return m, cmd
+ }
if m.searching {
switch msg.Type {
case tea.KeyEnter:
@@ -658,6 +704,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.filterInput.Focus()
m.updateTableHeight()
return m, nil
+ case "+":
+ m.addingTask = true
+ m.addInput.SetValue("")
+ m.addInput.Focus()
+ m.updateTableHeight()
+ return m, nil
case "t":
if row := m.tbl.SelectedRow(); row != nil {
idStr := ansi.Strip(row[1])
@@ -801,6 +853,7 @@ func (m Model) View() string {
m.tbl.HelpView(),
"enter/i: edit or expand cell",
"E: edit task",
+ "+: add task",
"s: toggle start/stop",
"d: mark task done",
"U: undo done",
@@ -875,6 +928,12 @@ func (m Model) View() string {
m.filterInput.View(),
)
}
+ if m.addingTask {
+ view = lipgloss.JoinVertical(lipgloss.Left,
+ view,
+ m.addInput.View(),
+ )
+ }
if m.searching {
view = lipgloss.JoinVertical(lipgloss.Left,
view,
@@ -1188,7 +1247,7 @@ func (m *Model) updateTableHeight() {
if m.cellExpanded {
h--
}
- if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing {
+ if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing || m.addingTask {
h--
}
if h < 1 {