| 38 | } |
| 39 | |
| 40 | func (m *Model) HandleUpdate(msg tea.Msg, cwdLocation string) (common.ModelAction, tea.Cmd) { |
| 41 | var action common.ModelAction |
| 42 | action = common.NoAction{} |
| 43 | var cmd tea.Cmd |
| 44 | if !m.IsOpen() { |
| 45 | slog.Error("HandleUpdate called on closed prompt") |
| 46 | return action, cmd |
| 47 | } |
| 48 | |
| 49 | switch msg := msg.(type) { |
| 50 | case tea.KeyPressMsg: |
| 51 | switch { |
| 52 | case slices.Contains(common.Hotkeys.ConfirmTyping, msg.String()): |
| 53 | action = m.handleConfirm(cwdLocation) |
| 54 | case slices.Contains(common.Hotkeys.CancelTyping, msg.String()): |
| 55 | m.Close() |
| 56 | default: |
| 57 | cmd = m.handleNormalKeyInput(msg) |
| 58 | } |
| 59 | default: |
| 60 | // Non keypress updates like Cursor Blink |
| 61 | m.textInput, cmd = m.textInput.Update(msg) |
| 62 | } |
| 63 | return action, cmd |
| 64 | } |
| 65 | |
| 66 | func (m *Model) handleConfirm(cwdLocation string) common.ModelAction { |
| 67 | // Pressing confirm on empty prompt will trigger close |