mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-20 01:02:02 +00:00
fix: dispose next edits on similar strings
This commit is contained in:
parent
8318fd7ec5
commit
6536ff441b
1 changed files with 17 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import com.intellij.diff.requests.SimpleDiffRequest
|
|||
import com.intellij.diff.tools.fragmented.UnifiedDiffChange
|
||||
import com.intellij.diff.tools.fragmented.UnifiedDiffViewer
|
||||
import com.intellij.diff.util.DiffUtil
|
||||
import com.intellij.diff.util.Side
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
|
|
@ -72,6 +73,12 @@ class CodeSuggestionDiffViewer(
|
|||
|
||||
override fun onAfterRediff() {
|
||||
val change = getClosestChange() ?: return
|
||||
val changeContent = getChangeContent(change)
|
||||
|
||||
if (normalizeString(getDocument(Side.LEFT).text).contains(normalizeString(changeContent))) {
|
||||
popup.dispose()
|
||||
return
|
||||
}
|
||||
|
||||
myEditor.component.preferredSize =
|
||||
Dimension(
|
||||
|
|
@ -159,6 +166,16 @@ class CodeSuggestionDiffViewer(
|
|||
mainEditor.document.removeDocumentListener(documentListener)
|
||||
}
|
||||
|
||||
private fun normalizeString(text: String): String {
|
||||
return text.replace("\\s+".toRegex(), "").lowercase()
|
||||
}
|
||||
|
||||
private fun getChangeContent(change: UnifiedDiffChange): String {
|
||||
val startOffset = change.lineFragment.startOffset2
|
||||
val endOffset = change.lineFragment.endOffset2
|
||||
return getDocument(Side.RIGHT).getText(TextRange(startOffset, endOffset))
|
||||
}
|
||||
|
||||
private fun getClosestChange(): UnifiedDiffChange? {
|
||||
val changes = diffChanges ?: emptyList()
|
||||
val cursorOffset = mainEditor.caretModel.offset
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue