summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-21 23:08:17 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-21 23:08:17 +0300
commit449f343c7da6071599c5c8266f3f9b43e0b0a315 (patch)
treee7f7de6ca05c5f9445b736020833c9f6d49265c6 /internal
parent4a47bd5907c1330a5bbedc13e384877c6ac71668 (diff)
Add filter editing hotkey
Diffstat (limited to 'internal')
-rw-r--r--internal/atable/table.go4
-rw-r--r--internal/ui/table.go39
2 files changed, 40 insertions, 3 deletions
diff --git a/internal/atable/table.go b/internal/atable/table.go
index c22d479..44f1c9f 100644
--- a/internal/atable/table.go
+++ b/internal/atable/table.go
@@ -85,8 +85,8 @@ func DefaultKeyMap() KeyMap {
key.WithHelp("b/pgup", "page up"),
),
PageDown: key.NewBinding(
- key.WithKeys("f", "pgdown", spacebar),
- key.WithHelp("f/pgdn", "page down"),
+ key.WithKeys("pgdown", spacebar),
+ key.WithHelp("pgdn", "page down"),
),
HalfPageUp: key.NewBinding(
key.WithKeys("u", "ctrl+u"),
diff --git a/internal/ui/table.go b/internal/ui/table.go
index bcfa017..3b1dacf 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -54,6 +54,9 @@ type Model struct {
dueID int
dueDate time.Time
+ filterEditing bool
+ filterInput textinput.Model
+
searching bool
searchInput textinput.Model
searchRegex *regexp.Regexp
@@ -112,6 +115,8 @@ func New(filters []string) (Model, error) {
m.dueDate = time.Now()
m.searchInput = textinput.New()
m.searchInput.Prompt = "search: "
+ m.filterInput = textinput.New()
+ m.filterInput.Prompt = "filter: "
m.defaultTheme = DefaultTheme()
m.theme = m.defaultTheme
@@ -349,6 +354,25 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return m, nil
}
+ if m.filterEditing {
+ switch msg.Type {
+ case tea.KeyEnter:
+ m.filters = strings.Fields(m.filterInput.Value())
+ m.filterEditing = false
+ m.filterInput.Blur()
+ m.reload()
+ m.updateTableHeight()
+ return m, nil
+ case tea.KeyEsc:
+ m.filterEditing = false
+ m.filterInput.Blur()
+ m.updateTableHeight()
+ return m, nil
+ }
+ var cmd tea.Cmd
+ m.filterInput, cmd = m.filterInput.Update(msg)
+ return m, cmd
+ }
if m.searching {
switch msg.Type {
case tea.KeyEnter:
@@ -511,6 +535,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
}
+ case "f":
+ m.filterEditing = true
+ m.filterInput.SetValue(strings.Join(m.filters, " "))
+ m.filterInput.Focus()
+ m.updateTableHeight()
+ return m, nil
case "t":
m.theme = RandomTheme()
m.applyTheme()
@@ -644,6 +674,7 @@ func (m Model) View() string {
"a: annotate task",
"A: replace annotations",
"p: set priority",
+ "f: change filter",
"t: randomize theme",
"T: reset theme",
"/, ?: search",
@@ -695,6 +726,12 @@ func (m Model) View() string {
m.tagsInput.View(),
)
}
+ if m.filterEditing {
+ view = lipgloss.JoinVertical(lipgloss.Left,
+ view,
+ m.filterInput.View(),
+ )
+ }
if m.searching {
view = lipgloss.JoinVertical(lipgloss.Left,
view,
@@ -980,7 +1017,7 @@ func (m *Model) updateTableHeight() {
if m.cellExpanded {
h--
}
- if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing {
+ if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.filterEditing {
h--
}
if h < 1 {