Add time undo and fill

This commit is contained in:
Martin Pander
2026-02-02 11:12:09 +01:00
parent fc8e9481c3
commit 9940316ace
5 changed files with 30 additions and 0 deletions

View File

@ -28,6 +28,7 @@ type Keymap struct {
Insert key.Binding Insert key.Binding
Tag key.Binding Tag key.Binding
Undo key.Binding Undo key.Binding
Fill key.Binding
StartStop key.Binding StartStop key.Binding
} }
@ -145,6 +146,11 @@ func NewKeymap() *Keymap {
key.WithHelp("undo", "Undo"), key.WithHelp("undo", "Undo"),
), ),
Fill: key.NewBinding(
key.WithKeys("f"),
key.WithHelp("fill", "Fill gaps"),
),
StartStop: key.NewBinding( StartStop: key.NewBinding(
key.WithKeys("s"), key.WithKeys("s"),
key.WithHelp("start/stop", "Start/Stop"), key.WithHelp("start/stop", "Start/Stop"),

View File

@ -83,6 +83,16 @@ func (p *TimePage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
editor := NewTimeEditorPage(p.common, interval) editor := NewTimeEditorPage(p.common, interval)
p.common.PushPage(p) p.common.PushPage(p)
return editor, editor.Init() return editor, editor.Init()
case key.Matches(msg, p.common.Keymap.Fill):
row := p.intervals.SelectedRow()
if row != nil {
interval := (*timewarrior.Interval)(row)
p.common.TimeW.FillInterval(interval.ID)
return p, tea.Batch(p.getIntervals(), doTick())
}
case key.Matches(msg, p.common.Keymap.Undo):
p.common.TimeW.Undo()
return p, tea.Batch(p.getIntervals(), doTick())
} }
} }

Binary file not shown.

View File

@ -30,6 +30,7 @@ type TimeWarrior interface {
ContinueInterval(id int) error ContinueInterval(id int) error
CancelTracking() error CancelTracking() error
DeleteInterval(id int) error DeleteInterval(id int) error
FillInterval(id int) error
ModifyInterval(interval *Interval, adjust bool) error ModifyInterval(interval *Interval, adjust bool) error
GetSummary(filter ...string) string GetSummary(filter ...string) string
GetActive() *Interval GetActive() *Interval
@ -218,6 +219,19 @@ func (ts *TimeSquire) DeleteInterval(id int) error {
return nil return nil
} }
func (ts *TimeSquire) FillInterval(id int) error {
ts.mutex.Lock()
defer ts.mutex.Unlock()
cmd := exec.Command(twBinary, append(ts.defaultArgs, []string{"fill", fmt.Sprintf("@%d", id)}...)...)
if err := cmd.Run(); err != nil {
slog.Error("Failed filling interval:", err)
return err
}
return nil
}
func (ts *TimeSquire) ModifyInterval(interval *Interval, adjust bool) error { func (ts *TimeSquire) ModifyInterval(interval *Interval, adjust bool) error {
ts.mutex.Lock() ts.mutex.Lock()
defer ts.mutex.Unlock() defer ts.mutex.Unlock()