The open source coding agent.
TypeScript
fix: use real cursor instead of virtual cursor
adamdotdevinb2f2c9ac37e0
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.goindex 509de6244e8..980d5262c81 100644--- a/packages/tui/internal/components/chat/editor.go+++ b/packages/tui/internal/components/chat/editor.go@@ -31,6 +31,7 @@ type EditorComponent interface {tea.Modeltea.ViewModelContent() string+ Cursor() *tea.CursorLines() intValue() stringLength() int@@ -407,6 +408,10 @@ func (m *editorComponent) Content() string {return content}+func (m *editorComponent) Cursor() *tea.Cursor {+ return m.textarea.Cursor()+}+func (m *editorComponent) View() string {width := m.widthif m.app.Session.ID == "" {@@ -694,6 +699,7 @@ func NewEditorComponent(app *app.App) EditorComponent {ta.Prompt = " "ta.ShowLineNumbers = falseta.CharLimit = -1+ ta.VirtualCursor = falseta = updateTextareaStyles(ta)m := &editorComponent{diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.goindex 6a56e20123f..7895adeac4e 100644--- a/packages/tui/internal/tui/tui.go+++ b/packages/tui/internal/tui/tui.go@@ -59,6 +59,8 @@ const interruptDebounceTimeout = 1 * time.Secondconst exitDebounceTimeout = 1 * time.Secondtype Model struct {+ tea.Model+ tea.CursorModelwidth, height intapp *app.Appmodal layout.Modal@@ -748,15 +750,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {return a, tea.Batch(cmds...)}-func (a Model) View() string {+func (a Model) View() (string, *tea.Cursor) {t := theme.CurrentTheme()var mainLayout string+ var editorX int+ var editorY intif a.app.Session.ID == "" {- mainLayout = a.home()+ mainLayout, editorX, editorY = a.home()} else {- mainLayout = a.chat()+ mainLayout, editorX, editorY = a.chat()}mainLayout = styles.NewStyle().Background(t.Background()).@@ -780,7 +784,12 @@ func (a Model) View() string {if theme.CurrentThemeUsesAnsiColors() {mainLayout = util.ConvertRGBToAnsi16Colors(mainLayout)}- return mainLayout + "\n" + a.status.View()++ cursor := a.editor.Cursor()+ cursor.Position.X += editorX+ cursor.Position.Y += editorY++ return mainLayout + "\n" + a.status.View(), cursor}func (a Model) Cleanup() {@@ -807,7 +816,7 @@ func (a Model) openFile(filepath string) (tea.Model, tea.Cmd) {return a, cmd}-func (a Model) home() string {+func (a Model) home() (string, int, int) {t := theme.CurrentTheme()effectiveWidth := a.width - 4baseStyle := styles.NewStyle().Background(t.Background())@@ -899,14 +908,21 @@ func (a Model) home() string {styles.WhitespaceStyle(t.Background()),)- editorX := (effectiveWidth - editorWidth) / 2+ editorX := max(0, (effectiveWidth-editorWidth)/2)editorY := (a.height / 2) + (mainHeight / 2) - 2if editorLines > 1 {+ content := a.editor.Content()+ editorHeight := lipgloss.Height(content)++ if editorY+editorHeight > a.height {+ difference := (editorY + editorHeight) - a.height+ editorY -= difference+ }mainLayout = layout.PlaceOverlay(editorX,editorY,- a.editor.Content(),+ content,mainLayout,)}@@ -924,10 +940,10 @@ func (a Model) home() string {)}- return mainLayout+ return mainLayout, editorX + 5, editorY + 2}-func (a Model) chat() string {+func (a Model) chat() (string, int, int) {effectiveWidth := a.width - 4t := theme.CurrentTheme()editorView := a.editor.View()@@ -944,14 +960,20 @@ func (a Model) chat() string {)mainLayout := messagesView + "\n" + editorView- editorX := (effectiveWidth - editorWidth) / 2+ editorX := max(0, (effectiveWidth-editorWidth)/2)+ editorY := a.height - editorHeightif lines > 1 {- editorY := a.height - editorHeight+ content := a.editor.Content()+ editorHeight := lipgloss.Height(content)+ if editorY+editorHeight > a.height {+ difference := (editorY + editorHeight) - a.height+ editorY -= difference+ }mainLayout = layout.PlaceOverlay(editorX,editorY,- a.editor.Content(),+ content,mainLayout,)}@@ -970,7 +992,7 @@ func (a Model) chat() string {)}- return mainLayout+ return mainLayout, editorX + 5, editorY + 2}func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {