Skip to content

The open source coding agent.

TypeScript

fix: file completions replaced wrong text when paths overlap (#378)

Aiden Cline0b1a8ae699a4
diff --git a/packages/tui/.gitignore b/packages/tui/.gitignore
new file mode 100644
index 00000000000..aac2e0bdc9a
--- /dev/null
+++ b/packages/tui/.gitignore
@@ -0,0 +1 @@
+opencode-test
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go
index d67a226fec5..b5d1cc0346a 100644
--- a/packages/tui/internal/components/chat/editor.go
+++ b/packages/tui/internal/components/chat/editor.go
@@ -80,8 +80,15 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
} else {
existingValue := m.textarea.Value()
- modifiedValue := strings.Replace(existingValue, msg.SearchString, msg.CompletionValue, 1)
- m.textarea.SetValue(modifiedValue + " ")
+
+ // Replace the current token (after last space)
+ lastSpaceIndex := strings.LastIndex(existingValue, " ")
+ if lastSpaceIndex == -1 {
+ m.textarea.SetValue(msg.CompletionValue + " ")
+ } else {
+ modifiedValue := existingValue[:lastSpaceIndex+1] + msg.CompletionValue
+ m.textarea.SetValue(modifiedValue + " ")
+ }
return m, nil
}
}