Просмотр исходного кода

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

Aiden Cline 8 месяцев назад
Родитель
Сommit
0b1a8ae699
2 измененных файлов с 10 добавлено и 2 удалено
  1. 1 0
      packages/tui/.gitignore
  2. 9 2
      packages/tui/internal/components/chat/editor.go

+ 1 - 0
packages/tui/.gitignore

@@ -0,0 +1 @@
+opencode-test

+ 9 - 2
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
 		}
 	}