on main help sign in
feat(bangmode): allow prefixing a string with bangmode
commitee47eb808cfeedafac0aba2d2acc2be9f2c9a73e authorKieran Klukas <kieran@dunkirk.sh> dateFri 19 Jun 2026, 15:43 (4 months ago) parentcf0d7c2
1 file changed+12−5
internal/ui/model/ui.go+12−5
internal/ui/model/ui.go+12−5
@@ -2181,13 +2181,20 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
21812181 prevHeight := m.textarea.Height()
21822182 cmds = append(cmds, m.updateTextareaWithPrevHeight(msg, prevHeight))
21832183
2184− // Bang mode: enter when "!" typed on empty prompt, exit on
2185− // backspace clearing the last character.
2184+ // Bang mode: enter when "!" is typed at the start of the
2185+ // prompt (either on an empty prompt or prepended to existing
2186+ // text). Exit on backspace clearing the last character.
21862187 newVal := m.textarea.Value()
2187− if !m.bangMode && strings.TrimSpace(newVal) == "!" {
2188+ if !m.bangMode && strings.HasPrefix(newVal, "!") && !strings.HasPrefix(curValue, "!") {
21882189 m.bangMode = true
2189− m.bangWasEmpty = true
2190− m.textarea.Reset()
2190+ m.bangWasEmpty = len(strings.TrimSpace(curValue)) == 0
2191+ // Strip the leading "!" from the textarea while preserving
2192+ // the cursor position relative to the command text.
2193+ col := m.textarea.Column()
2194+ line := m.textarea.Line()
2195+ m.textarea.SetValue(newVal[1:])
2196+ m.textarea.SetCursorColumn(max(0, col-1))
2197+ _ = line // cursor line doesn't change; first char removed
21912198 yolo := m.com.Workspace.PermissionSkipRequests()
21922199 m.setEditorPrompt(yolo)
21932200 } else if m.bangMode && newVal == "" && curValue != "" {