[spellchecker] ChangeTo: disable when document changed

Fixes EA-654994 - IOOBE: CharSequenceSubSequence.<init>

GitOrigin-RevId: 22b0e05a72db4dd083bbcca816ba25994e9e2c14
This commit is contained in:
Tagir Valeev
2022-11-14 19:29:24 +00:00
committed by intellij-monorepo-bot
parent 0d121391d5
commit 8a4487fa69
@@ -7,7 +7,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.codeInsight.intention.choice.ChoiceTitleIntentionAction
import com.intellij.codeInsight.intention.choice.ChoiceVariantIntentionAction
import com.intellij.codeInsight.intention.choice.DefaultIntentionActionWithChoice
import com.intellij.codeInsight.intention.impl.config.LazyEditor
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsSafe
@@ -50,6 +50,7 @@ class ChangeTo(typo: String, element: PsiElement, private val range: TextRange)
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile): Boolean {
val suggestions = getSuggestions(project)
if (suggestions.size <= index) return false
if (getRange(file.viewProvider.document) == null) return false
suggestion = suggestions[index]
return true
}
@@ -57,17 +58,22 @@ class ChangeTo(typo: String, element: PsiElement, private val range: TextRange)
override fun applyFix(project: Project, file: PsiFile, editor: Editor?) {
val suggestion = suggestion ?: return
val myEditor = editor ?: LazyEditor(file)
val document = file.viewProvider.document
val myRange = getRange(document) ?: return
val myElement = pointer.element ?: return
val myRange = range.shiftRight(myElement.startOffset)
UpdateHighlightersUtil.removeHighlightersWithExactRange(document, project, myRange)
val myText = myEditor.document.getText(myRange)
if (myText != typo) return
document.replaceString(myRange.startOffset, myRange.endOffset, suggestion)
}
private fun getRange(document: Document): TextRange? {
val element = pointer.element ?: return null
val range = range.shiftRight(element.startOffset)
if (range.startOffset < 0 || range.endOffset > document.textLength) return null
UpdateHighlightersUtil.removeHighlightersWithExactRange(myEditor.document, project, myRange)
myEditor.document.replaceString(myRange.startOffset, myRange.endOffset, suggestion)
val text = document.getText(range)
if (text != typo) return null
return range
}
override fun getFileModifierForPreview(target: PsiFile): FileModifier {