@@ -3,6 +3,7 @@ package model
7 tea "charm.land/bubbletea/v2"
8 tea "charm.land/bubbletea/v2"
@@ -36,6 +37,9 @@ func (m *UI) loadPromptHistory() tea.Cmd {
36 if text := msg.Content().Text; text != "" {
37 if text := msg.Content().Text; text != "" {
37 texts = append(texts, text)
38 texts = append(texts, text)
40+ for _, sc := range msg.ShellCommands() {
41+ texts = append(texts, "!"+sc.Command)
40 return promptHistoryLoadedMsg{messages: texts}
44 return promptHistoryLoadedMsg{messages: texts}
@@ -93,6 +97,7 @@ func (m *UI) handleHistoryEscape(msg tea.Msg) tea.Cmd {
93 m.promptHistory.index = -1
97 m.promptHistory.index = -1
94 m.textarea.Reset()
98 m.textarea.Reset()
95 m.textarea.InsertString(m.promptHistory.draft)
99 m.textarea.InsertString(m.promptHistory.draft)
100+ m.syncBangModeFromTextarea()
96 return m.updateTextareaWithPrevHeight(nil, prevHeight)
101 return m.updateTextareaWithPrevHeight(nil, prevHeight)
@@ -108,6 +113,26 @@ func (m *UI) updateHistoryDraft(oldValue string) {
116+// syncBangModeFromTextarea engages or disengages bang mode based on
117+// whether the current textarea value starts with "!". The "!" prefix
118+// is stripped when entering bang mode and re-added when leaving it so
119+// the visible text always reflects the correct state.
120+func (m *UI) syncBangModeFromTextarea() {
121+ val := m.textarea.Value()
122+ hasBang := strings.HasPrefix(val, "!")
123+ if hasBang && !m.bangMode {
125+ m.bangWasEmpty = false
126+ m.textarea.SetValue(val[1:])
127+ m.textarea.MoveToBegin()
128+ } else if !hasBang && m.bangMode {
130+ m.bangWasEmpty = false
132+ yolo := m.com.Workspace.PermissionSkipRequests()
133+ m.setEditorPrompt(yolo)
111// historyPrev changes the text area content to the previous message in the history
136// historyPrev changes the text area content to the previous message in the history
112// it returns false if it could not find the previous message.
137// it returns false if it could not find the previous message.
113func (m *UI) historyPrev() bool {
138func (m *UI) historyPrev() bool {
@@ -125,6 +150,7 @@ func (m *UI) historyPrev() bool {
125 m.textarea.Reset()
150 m.textarea.Reset()
126 m.textarea.InsertString(m.promptHistory.messages[nextIndex])
151 m.textarea.InsertString(m.promptHistory.messages[nextIndex])
127 m.textarea.MoveToBegin()
152 m.textarea.MoveToBegin()
153+ m.syncBangModeFromTextarea()
128 return true
154 return true
@@ -139,11 +165,13 @@ func (m *UI) historyNext() bool {
139 m.promptHistory.index = -1
165 m.promptHistory.index = -1
140 m.textarea.Reset()
166 m.textarea.Reset()
141 m.textarea.InsertString(m.promptHistory.draft)
167 m.textarea.InsertString(m.promptHistory.draft)
168+ m.syncBangModeFromTextarea()
142 return true
169 return true
144 m.promptHistory.index = nextIndex
171 m.promptHistory.index = nextIndex
145 m.textarea.Reset()
172 m.textarea.Reset()
146 m.textarea.InsertString(m.promptHistory.messages[nextIndex])
173 m.textarea.InsertString(m.promptHistory.messages[nextIndex])
174+ m.syncBangModeFromTextarea()
147 return true
175 return true