handleEnter implements the three-way Enter dispatch. Alt+Enter inserts a newline; command-level Enter on an args-taking command advances to the arg popover (same model as Tab); plain Enter commits.
(msg tea.KeyMsg)
| 211 | // newline; mid-turn Enter queues the prompt (queuePrompt); command-level Enter |
| 212 | // on an args-taking command advances to the arg popover (same model as Tab); |
| 213 | // plain Enter commits. |
| 214 | func (m Model) handleEnter(msg tea.KeyMsg) (tea.Model, tea.Cmd) { |
| 215 | if msg.Alt { |
| 216 | // Strip the Alt flag before forwarding: the textarea's InsertNewline |
| 217 | // binding matches "enter", and an alt-flagged KeyEnter ("alt+enter") |
| 218 | // matches no binding at all, falling through to a rune-insert no-op. |
| 219 | return m.forwardToTextarea(tea.KeyMsg{Type: tea.KeyEnter}) |
| 220 | } |
| 221 | if m.phase.active() { |
| 222 | return m.queuePrompt() |
| 223 | } |
| 224 | sel, hasSel := m.currentSuggestion() |
| 225 | // Command-level Enter on an args-taking command advances to the arg |
| 226 | // popover (same shape as Tab on a unique match). |
| 227 | if hasSel && !m.suggestArgLevel { |
| 228 | if c := commandByName(sel.value); c != nil && c.args != nil { |
| 229 | m.setPromptText(sel.value + " ") |
| 230 | return m, nil |
| 231 | } |
| 232 | } |
| 233 | // Plain commit. Value() expands chip labels to full paste content (→ LLM); |
| 234 | // DisplayValue() keeps them collapsed (→ echo + history). A popover |
| 235 | // selection overrides both so a command prefix + Enter submits the full |
| 236 | // command and no chips leak into a slash command. |
| 237 | var sendText, echoText string |
| 238 | var entry promptEntry |
| 239 | if hasSel { |
| 240 | if m.suggestArgLevel { |
| 241 | sendText = m.activeCmd + " " + sel.value |
| 242 | } else { |
| 243 | sendText = sel.value |
| 244 | } |
| 245 | echoText = sendText |
| 246 | entry = promptEntry{display: sendText} |
| 247 | } else { |
| 248 | sendText = strings.TrimSpace(m.ta.Value()) |
| 249 | echoText = strings.TrimSpace(m.ta.DisplayValue()) |
| 250 | entry = m.ta.Entry() |
| 251 | } |
| 252 | if sendText == "" { |
| 253 | return m, nil |
| 254 | } |
| 255 | m.ta.Reset() |
| 256 | m.closePopover() |
| 257 | return m.submit(sendText, echoText, entry) |
| 258 | } |
| 259 | |
| 260 | // queuePrompt stashes the textarea contents to auto-submit when the running turn |
no test coverage detected