From 2f01792f3b4fc40d5ddff8cf93a3bac3d500a210 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 2 Sep 2026 07:26:07 +0000 Subject: [PATCH 1/2] fix: prevent hyphen from stepping date in TUI date picker The "-" key typed in the date field is now swallowed instead of stepping the date backward or being inserted as a literal character. This fixes #368 where users could not enter the YYYY-MM-DD delimiter. --- internal/tui/datetime.go | 8 +++++--- internal/tui/datetime_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/tui/datetime.go b/internal/tui/datetime.go index 6cad72ee..ea119e7d 100644 --- a/internal/tui/datetime.go +++ b/internal/tui/datetime.go @@ -237,6 +237,11 @@ func (p *dateTimePicker) handleKey(msg tea.KeyPressMsg) tea.Cmd { p.shiftDate(days) return nil } + // "-" cannot appear in a YYYY-MM-DD date, so swallow it here + // instead of letting it through to the text input (hey-cli#368) + if msg.String() == "-" { + return nil + } var cmd tea.Cmd p.dateInput, cmd = p.dateInput.Update(msg) return cmd @@ -263,13 +268,10 @@ func dateStep(msg tea.KeyPressMsg) (days int, stepped bool) { case tea.KeyUp: return 1, true case tea.KeyDown: - return -1, true } switch msg.String() { case "+", "=": return 1, true - case "-": - return -1, true } return 0, false } diff --git a/internal/tui/datetime_test.go b/internal/tui/datetime_test.go index 8951cb7f..073077de 100644 --- a/internal/tui/datetime_test.go +++ b/internal/tui/datetime_test.go @@ -68,15 +68,15 @@ func TestDateTimePickerStepsTheDateByADay(t *testing.T) { t.Errorf("after up, date() = %q, want 2026-08-23", got) } - picker.handleKey(tea.KeyPressMsg{Code: tea.KeyDown}) - picker.handleKey(tea.KeyPressMsg{Code: tea.KeyDown}) - if got := picker.date(); got != "2026-08-21" { - t.Errorf("after two downs, date() = %q, want 2026-08-21", got) + // "-" no longer steps date (hey-cli#368) + typeInto(t, picker, "-") + if got := picker.date(); got != "2026-08-23" { + t.Errorf("after -, date() = %q, want unchanged", got) } typeInto(t, picker, "+") - if got := picker.date(); got != "2026-08-22" { - t.Errorf("after +, date() = %q, want 2026-08-22", got) + if got := picker.date(); got != "2026-08-24" { + t.Errorf("after +, date() = %q, want 2026-08-24", got) } picker.dateInput.SetValue("next tuesday") From 64280105ebf67504da7c830c4070feb98beeeccb Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 9 Sep 2026 20:29:39 -0700 Subject: [PATCH 2/2] Type the hyphen into the date field instead of dropping it The bug in hey-cli#368 is that a date cannot be typed: "-" was bound as the step-back key, so the separator moved the date instead of landing in the field. Swallowing the key stops the step but still leaves the field without its separator, and it took the down arrow's step with it. "-" now goes through to the input like any other character, and the arrows keep stepping the day both ways as the help says they do. --- internal/tui/datetime.go | 12 ++++-------- internal/tui/datetime_test.go | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/internal/tui/datetime.go b/internal/tui/datetime.go index ea119e7d..4f447ff4 100644 --- a/internal/tui/datetime.go +++ b/internal/tui/datetime.go @@ -237,11 +237,6 @@ func (p *dateTimePicker) handleKey(msg tea.KeyPressMsg) tea.Cmd { p.shiftDate(days) return nil } - // "-" cannot appear in a YYYY-MM-DD date, so swallow it here - // instead of letting it through to the text input (hey-cli#368) - if msg.String() == "-" { - return nil - } var cmd tea.Cmd p.dateInput, cmd = p.dateInput.Update(msg) return cmd @@ -260,14 +255,15 @@ func (p *dateTimePicker) handleKey(msg tea.KeyPressMsg) tea.Cmd { } } -// dateStep is the day-at-a-time keys. Both pairs are here because neither means anything -// else on a date field: the arrows are unbound in a single-line text input, and a + or a - -// cannot appear in YYYY-MM-DD, so typing one is only ever a step. +// dateStep is the day-at-a-time keys. The arrows are unbound in a single-line text input, +// and a + cannot appear in YYYY-MM-DD, so typing one is only ever a step. A - is the date's +// own separator, so it is typed into the field like any other character (hey-cli#368). func dateStep(msg tea.KeyPressMsg) (days int, stepped bool) { switch msg.Key().Code { case tea.KeyUp: return 1, true case tea.KeyDown: + return -1, true } switch msg.String() { case "+", "=": diff --git a/internal/tui/datetime_test.go b/internal/tui/datetime_test.go index 073077de..a23d7d26 100644 --- a/internal/tui/datetime_test.go +++ b/internal/tui/datetime_test.go @@ -68,15 +68,15 @@ func TestDateTimePickerStepsTheDateByADay(t *testing.T) { t.Errorf("after up, date() = %q, want 2026-08-23", got) } - // "-" no longer steps date (hey-cli#368) - typeInto(t, picker, "-") - if got := picker.date(); got != "2026-08-23" { - t.Errorf("after -, date() = %q, want unchanged", got) + picker.handleKey(tea.KeyPressMsg{Code: tea.KeyDown}) + picker.handleKey(tea.KeyPressMsg{Code: tea.KeyDown}) + if got := picker.date(); got != "2026-08-21" { + t.Errorf("after two downs, date() = %q, want 2026-08-21", got) } typeInto(t, picker, "+") - if got := picker.date(); got != "2026-08-24" { - t.Errorf("after +, date() = %q, want 2026-08-24", got) + if got := picker.date(); got != "2026-08-22" { + t.Errorf("after +, date() = %q, want 2026-08-22", got) } picker.dateInput.SetValue("next tuesday") @@ -86,6 +86,17 @@ func TestDateTimePickerStepsTheDateByADay(t *testing.T) { } } +func TestDateTimePickerTypesTheDateSeparator(t *testing.T) { + picker := testPicker() + picker.focusFirst() + picker.dateInput.SetValue("2026-08") + + typeInto(t, picker, "-22") + if got := picker.date(); got != "2026-08-22" { + t.Errorf("after typing -22, date() = %q, want 2026-08-22", got) + } +} + func TestDateTimePickerAllDayHidesTheTimeAndTheZone(t *testing.T) { picker := testPicker() picker.setZoneName("Europe/Zagreb")