Skip to content

Commit

Permalink
fix(tui): Only open event editor when there is an event selected
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Apr 6, 2024
1 parent 20d7438 commit baf084f
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions internal/control/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,23 +736,26 @@ func NewController(
}),
"<cr>": action.NewSimple(func() string { return "open the event editor" }, func() {
event := controller.data.GetCurrentDay().Current
if event != nil {
if controller.data.EventEditor != nil {
log.Warn().Msgf("was about to construct new event editor but still have old one")
return
}
newEventEditor, err := editors.ConstructEditor("event", event, nil, func() (bool, bool) { return true, true })
if err != nil {
log.Warn().Err(err).Msgf("unable to construct event editor")
return
}
var ok bool
controller.data.EventEditor, ok = newEventEditor.(*editors.Composite)
if !ok {
log.Error().Msgf("something went _really_ wrong and the editor constructed for the event is _not_ a composite editor but a %T", newEventEditor)
controller.data.EventEditor = nil
return
}
if event == nil {
log.Warn().Msgf("ignoring event editing request since no current event selected")
return
}

if controller.data.EventEditor != nil {
log.Warn().Msgf("was about to construct new event editor but still have old one")
return
}
newEventEditor, err := editors.ConstructEditor("event", event, nil, func() (bool, bool) { return true, true })
if err != nil {
log.Warn().Err(err).Msgf("unable to construct event editor")
return
}
var ok bool
controller.data.EventEditor, ok = newEventEditor.(*editors.Composite)
if !ok {
log.Error().Msgf("something went _really_ wrong and the editor constructed for the event is _not_ a composite editor but a %T", newEventEditor)
controller.data.EventEditor = nil
return
}

eventEditorRenderer := ui.NewConstrainedRenderer(renderer, editorDimensions)
Expand Down

0 comments on commit baf084f

Please sign in to comment.