fix(dialog): commands: execute command handlers properly

Ayman Bagabas created

Change summary

internal/ui/dialog/commands.go | 6 +++++-
internal/ui/model/ui.go        | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)

Detailed changes

internal/ui/dialog/commands.go 🔗

@@ -149,7 +149,11 @@ func (c *Commands) Update(msg tea.Msg) tea.Msg {
 		case key.Matches(msg, c.keyMap.Select):
 			if selectedItem := c.list.SelectedItem(); selectedItem != nil {
 				if item, ok := selectedItem.(*CommandItem); ok && item != nil {
-					return item.Cmd.Handler(item.Cmd) // Huh??
+					// TODO: Please unravel this mess later and the Command
+					// Handler design.
+					if cmd := item.Cmd.Handler(item.Cmd); cmd != nil { // Huh??
+						return cmd()
+					}
 				}
 			}
 		case key.Matches(msg, c.keyMap.Tab):

internal/ui/model/ui.go 🔗

@@ -441,6 +441,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
 			}
 		case dialog.ToggleHelpMsg:
 			m.help.ShowAll = !m.help.ShowAll
+			m.dialog.RemoveDialog(dialog.CommandsID)
 		case dialog.QuitMsg:
 			cmds = append(cmds, tea.Quit)
 		}