summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 22:33:29 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 22:33:29 +0300
commitffca76599b02b21ac34e8a2ec598e93653f338f9 (patch)
treeb9405362b5f6ed086ee09c07905004faa3eb5a57 /internal
parent67289708848ff191ff9482bb745980c6c780beaa (diff)
Add navigation hotkeys
Diffstat (limited to 'internal')
-rw-r--r--internal/atable/table.go4
-rw-r--r--internal/ui/table_test.go50
2 files changed, 52 insertions, 2 deletions
diff --git a/internal/atable/table.go b/internal/atable/table.go
index d6ea99d..8f2b3c0 100644
--- a/internal/atable/table.go
+++ b/internal/atable/table.go
@@ -97,8 +97,8 @@ func DefaultKeyMap() KeyMap {
key.WithHelp("d", "½ page down"),
),
GotoTop: key.NewBinding(
- key.WithKeys("home", "g"),
- key.WithHelp("g/home", "go to start"),
+ key.WithKeys("home", "g", "0"),
+ key.WithHelp("g/home/0", "go to start"),
),
GotoBottom: key.NewBinding(
key.WithKeys("end", "G"),
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index ea904b3..7b3dd72 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -381,3 +381,53 @@ func TestPriorityHotkey(t *testing.T) {
t.Fatalf("priority not set: %q", data)
}
}
+
+func TestNavigationHotkeys(t *testing.T) {
+ tmp := t.TempDir()
+ taskPath := filepath.Join(tmp, "task")
+
+ script := "#!/bin/sh\n" +
+ "if echo \"$@\" | grep -q export; then\n" +
+ " echo '{\"id\":1,\"uuid\":\"x\",\"description\":\"d1\",\"status\":\"pending\",\"entry\":\"\",\"priority\":\"\",\"urgency\":0}'\n" +
+ " echo '{\"id\":2,\"uuid\":\"y\",\"description\":\"d2\",\"status\":\"pending\",\"entry\":\"\",\"priority\":\"\",\"urgency\":0}'\n" +
+ " exit 0\n" +
+ "fi\n"
+
+ if err := os.WriteFile(taskPath, []byte(script), 0o755); err != nil {
+ t.Fatal(err)
+ }
+
+ origPath := os.Getenv("PATH")
+ os.Setenv("PATH", tmp+":"+origPath)
+ t.Cleanup(func() { os.Setenv("PATH", origPath) })
+
+ os.Setenv("TASKDATA", tmp)
+ os.Setenv("TASKRC", "/dev/null")
+ t.Cleanup(func() {
+ os.Unsetenv("TASKDATA")
+ os.Unsetenv("TASKRC")
+ })
+
+ m, err := New(nil)
+ if err != nil {
+ t.Fatalf("New: %v", err)
+ }
+
+ mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
+ m = mv.(Model)
+ if m.tbl.Cursor() != 1 {
+ t.Fatalf("down: got cursor %d", m.tbl.Cursor())
+ }
+
+ mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'0'}})
+ m = mv.(Model)
+ if m.tbl.Cursor() != 0 {
+ t.Fatalf("0 hotkey: expected 0 got %d", m.tbl.Cursor())
+ }
+
+ mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'G'}})
+ m = mv.(Model)
+ if m.tbl.Cursor() != 1 {
+ t.Fatalf("G hotkey: expected 1 got %d", m.tbl.Cursor())
+ }
+}