mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
IDEA-302967 Fix freeze in Features Suggester
Invoking CopyPasteManager methods during write action is not safe. GitOrigin-RevId: f3e032c111bbe8f8bceba67f87ea30a874e5b4b4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ceb2e26bfe
commit
60d7bbf49e
@@ -1,15 +1,12 @@
|
||||
package training.featuresSuggester.suggesters
|
||||
|
||||
import com.intellij.openapi.ide.CopyPasteManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import training.featuresSuggester.FeatureSuggesterBundle
|
||||
import training.featuresSuggester.NoSuggestion
|
||||
import training.featuresSuggester.SuggesterSupport
|
||||
import training.featuresSuggester.SuggestingUtils.asString
|
||||
import training.featuresSuggester.Suggestion
|
||||
import training.featuresSuggester.actions.*
|
||||
import training.util.WeakReferenceDelegator
|
||||
import java.awt.datatransfer.DataFlavor
|
||||
|
||||
class IntroduceVariableSuggester : AbstractFeatureSuggester() {
|
||||
override val id: String = "Introduce variable"
|
||||
@@ -49,7 +46,7 @@ class IntroduceVariableSuggester : AbstractFeatureSuggester() {
|
||||
when (action) {
|
||||
is BeforeEditorTextRemovedAction -> {
|
||||
with(action) {
|
||||
val deletedText = getCopiedContent(textFragment.text) ?: return NoSuggestion
|
||||
val deletedText = textFragment.text.takeIf { it.isNotBlank() }?.trim() ?: return NoSuggestion
|
||||
val psiFile = this.psiFile ?: return NoSuggestion
|
||||
val contentOffset = caretOffset + textFragment.text.indexOfFirst { it != ' ' && it != '\n' }
|
||||
val curElement = psiFile.findElementAt(contentOffset) ?: return NoSuggestion
|
||||
@@ -60,6 +57,12 @@ class IntroduceVariableSuggester : AbstractFeatureSuggester() {
|
||||
}
|
||||
}
|
||||
}
|
||||
is EditorCutAction -> {
|
||||
val data = extractedExprData ?: return NoSuggestion
|
||||
if (data.exprText != action.text.trim()) {
|
||||
extractedExprData = null
|
||||
}
|
||||
}
|
||||
is ChildReplacedAction -> {
|
||||
if (extractedExprData == null) return NoSuggestion
|
||||
with(action) {
|
||||
@@ -105,20 +108,6 @@ class IntroduceVariableSuggester : AbstractFeatureSuggester() {
|
||||
return NoSuggestion
|
||||
}
|
||||
|
||||
private fun getCopiedContent(text: String): String? {
|
||||
if (text.isBlank()) return null
|
||||
val content = text.trim()
|
||||
val copyPasteManager = CopyPasteManager.getInstance()
|
||||
return if (copyPasteManager.areDataFlavorsAvailable(DataFlavor.stringFlavor) &&
|
||||
content == copyPasteManager.contents?.asString()?.trim()
|
||||
) {
|
||||
content
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun SuggesterSupport.isVariableDeclarationAdded(action: ChildReplacedAction): Boolean {
|
||||
return isExpressionStatement(action.oldChild) && isVariableDeclaration(action.newChild)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user