@@ -53,6 +53,8 @@ type editor struct {
5353 suggestion string
5454 hasSuggestion bool
5555 cursorHidden bool
56+ // userTyped tracks whether the user has manually typed content (vs loaded from history)
57+ userTyped bool
5658}
5759
5860// New creates a new editor component
@@ -259,6 +261,7 @@ func (e *editor) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
259261 e .textarea .SetValue (prev )
260262 e .textarea .MoveToEnd ()
261263 e .textarea .Reset ()
264+ e .userTyped = false // Reset after sending
262265 e .refreshSuggestion ()
263266 return e , core .CmdHandler (SendMsg {Content : prev })
264267 }
@@ -283,6 +286,7 @@ func (e *editor) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
283286 // Normal Enter submit (no textarea change): send current value.
284287 if value != "" && ! e .working {
285288 e .textarea .Reset ()
289+ e .userTyped = false // Reset after sending
286290 e .refreshSuggestion ()
287291 return e , core .CmdHandler (SendMsg {Content : value })
288292 }
@@ -291,15 +295,23 @@ func (e *editor) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
291295 case "ctrl+c" :
292296 return e , tea .Quit
293297 case "up" :
294- e .textarea .SetValue (e .hist .Previous ())
295- e .textarea .MoveToEnd ()
296- e .refreshSuggestion ()
297- return e , nil
298+ // Only navigate history if the user hasn't manually typed content
299+ if ! e .userTyped {
300+ e .textarea .SetValue (e .hist .Previous ())
301+ e .textarea .MoveToEnd ()
302+ e .refreshSuggestion ()
303+ return e , nil
304+ }
305+ // Otherwise, let the textarea handle cursor navigation
298306 case "down" :
299- e .textarea .SetValue (e .hist .Next ())
300- e .textarea .MoveToEnd ()
301- e .refreshSuggestion ()
302- return e , nil
307+ // Only navigate history if the user hasn't manually typed content
308+ if ! e .userTyped {
309+ e .textarea .SetValue (e .hist .Next ())
310+ e .textarea .MoveToEnd ()
311+ e .refreshSuggestion ()
312+ return e , nil
313+ }
314+ // Otherwise, let the textarea handle cursor navigation
303315 default :
304316 for _ , completion := range e .completions {
305317 if msg .String () == completion .Trigger () {
@@ -312,11 +324,22 @@ func (e *editor) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
312324 }
313325 }
314326
327+ prevValue := e .textarea .Value ()
315328 var cmd tea.Cmd
316329 e .textarea , cmd = e .textarea .Update (msg )
317330 cmds = append (cmds , cmd )
318331
332+ // If the value changed due to user input (not history navigation), mark as user typed
319333 if keyMsg , ok := msg .(tea.KeyPressMsg ); ok {
334+ // Check if content changed and it wasn't a history navigation key
335+ if e .textarea .Value () != prevValue && keyMsg .String () != "up" && keyMsg .String () != "down" {
336+ e .userTyped = true
337+ }
338+
339+ // Also check if textarea became empty - reset userTyped flag
340+ if e .textarea .Value () == "" {
341+ e .userTyped = false
342+ }
320343 if keyMsg .String () == "space" {
321344 e .completionWord = ""
322345 e .currentCompletion = nil
0 commit comments