@@ -17,6 +17,7 @@ import (
22 "charm.land/bubbles/v2/help"
23 "charm.land/bubbles/v2/help"
@@ -2182,19 +2183,24 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
2182 cmds = append(cmds, m.updateTextareaWithPrevHeight(msg, prevHeight))
2183 cmds = append(cmds, m.updateTextareaWithPrevHeight(msg, prevHeight))
2184 // Bang mode: enter when "!" is typed at the start of the
2185 // Bang mode: enter when "!" is typed at the start of the
2186+ // prompt, optionally preceded by whitespace (either on an
2185− // prompt (either on an empty prompt or prepended to existing
2187+ // empty/whitespace-only prompt or prepended to existing text).
2186− // text). Exit on backspace clearing the last character.
2188+ // Exit on backspace clearing the last character.
2187 newVal := m.textarea.Value()
2189 newVal := m.textarea.Value()
2190+ trimmedNew := strings.TrimLeftFunc(newVal, unicode.IsSpace)
2191+ trimmedCur := strings.TrimLeftFunc(curValue, unicode.IsSpace)
2188− if !m.bangMode && strings.HasPrefix(newVal, "!") && !strings.HasPrefix(curValue, "!") {
2192+ if !m.bangMode && strings.HasPrefix(trimmedNew, "!") && !strings.HasPrefix(trimmedCur, "!") {
2189 m.bangMode = true
2193 m.bangMode = true
2190 m.bangWasEmpty = len(strings.TrimSpace(curValue)) == 0
2194 m.bangWasEmpty = len(strings.TrimSpace(curValue)) == 0
2191− // Strip the leading "!" from the textarea while preserving
2195+ // Strip leading whitespace and the "!" from the textarea
2192− // the cursor position relative to the command text.
2196+ // while preserving the cursor position relative to the
2193 col := m.textarea.Column()
2198 col := m.textarea.Column()
2194 line := m.textarea.Line()
2199 line := m.textarea.Line()
2195− m.textarea.SetValue(newVal[1:])
2200+ stripped := trimmedNew[1:]
2201+ m.textarea.SetValue(stripped)
2196− m.textarea.SetCursorColumn(max(0, col-1))
2202+ m.textarea.SetCursorColumn(max(0, col-(len(newVal)-len(stripped))))
2197− _ = line // cursor line doesn't change; first char removed
2203+ _ = line // cursor line doesn't change; prefix removed
2198 yolo := m.com.Workspace.PermissionSkipRequests()
2204 yolo := m.com.Workspace.PermissionSkipRequests()
2199 m.setEditorPrompt(yolo)
2205 m.setEditorPrompt(yolo)
2200 } else if m.bangMode && newVal == "" && curValue != "" {
2206 } else if m.bangMode && newVal == "" && curValue != "" {