Fix deduplication bug in autocomplete.

This commit is contained in:
lidongming 2024-11-20 14:24:01 +08:00
parent c6f2abd940
commit 0dafb5240f

View file

@ -129,6 +129,13 @@ class AutocompleteService(private val project: Project) {
document.getText(com.intellij.openapi.util.TextRange(caretOffset, document.textLength))
}
// Determine the index of a newline character within the text following the cursor.
val newlineIndex = textAfterCursor.indexOf("\r\n").takeIf { it >= 0 } ?: textAfterCursor.indexOf('\n')
// If a newline character is found and the current line is not empty, truncate the text at that point.
if (newlineIndex > 0) {
textAfterCursor = textAfterCursor.substring(0, newlineIndex)
}
val indexOfTextAfterCursorInCompletion = completion.indexOf(textAfterCursor)
if (indexOfTextAfterCursorInCompletion > 0) {
return@runReadAction completion.slice(0..indexOfTextAfterCursorInCompletion - 1)