From 9c3a7712388ec8619a12f29e84606d9ae24d6a3b Mon Sep 17 00:00:00 2001 From: tauraamui Date: Thu, 4 Dec 2025 12:25:00 +0000 Subject: [PATCH] fix: restore cursor position after setting field contents back --- internal/tui/components/chat/editor/editor.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 58c2ba84f26f1ea911c7596479b1dcf358793a64..73ea00110b4b0bba8a6d3919b4cd5bf4ac898afc 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -207,12 +207,17 @@ func (m *editorCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) { break } m.history = InitialiseHistory(m.textarea.Value(), msgs) - // m.textarea.SetValue(m.history.Value()) return m, nil case CloseHistoryMsg: + cursorCurrentLine := m.textarea.Line() + cursorLineInfo := m.textarea.LineInfo() m.textarea.SetValue(msg.valueToSet) + m.textarea.MoveToBegin() + for range cursorCurrentLine { + m.textarea.CursorDown() + } + m.textarea.SetCursorColumn(cursorLineInfo.ColumnOffset - cursorLineInfo.StartColumn) m.history = nil - // return m, nil case ScrollHistoryUp: if m.inHistoryMode() { m.history.ScrollUp() @@ -325,6 +330,8 @@ func (m *editorCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) { cmds = append(cmds, util.CmdHandler(CloseHistoryMsg{ valueToSet: m.textarea.Value(), })) + cmds = append(cmds, util.CmdHandler(msg)) + return m, tea.Sequence(cmds...) } }