Introduce Variable: Move caret to the end of declaration when replacing "statement" expression
#KT-10663 Fixed
This commit is contained in:
+15
-10
@@ -500,16 +500,6 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
|
|||||||
|
|
||||||
val allOccurrences = occurrencesToReplace ?: expression.findOccurrences(occurrenceContainer)
|
val allOccurrences = occurrencesToReplace ?: expression.findOccurrences(occurrenceContainer)
|
||||||
|
|
||||||
fun postProcess(declaration: KtDeclaration) {
|
|
||||||
if (typeArgumentList == null) return
|
|
||||||
val initializer = when (declaration) {
|
|
||||||
is KtProperty -> declaration.initializer
|
|
||||||
is KtDestructuringDeclaration -> declaration.initializer
|
|
||||||
else -> null
|
|
||||||
} ?: return
|
|
||||||
runWriteAction { addTypeArgumentsIfNeeded(initializer, typeArgumentList) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val callback = Pass<OccurrencesChooser.ReplaceChoice> { replaceChoice ->
|
val callback = Pass<OccurrencesChooser.ReplaceChoice> { replaceChoice ->
|
||||||
val allReplaces = when (replaceChoice) {
|
val allReplaces = when (replaceChoice) {
|
||||||
OccurrencesChooser.ReplaceChoice.ALL -> allOccurrences
|
OccurrencesChooser.ReplaceChoice.ALL -> allOccurrences
|
||||||
@@ -525,6 +515,21 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
|
|||||||
commonContainer = container
|
commonContainer = container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun postProcess(declaration: KtDeclaration) {
|
||||||
|
if (typeArgumentList != null) {
|
||||||
|
val initializer = when (declaration) {
|
||||||
|
is KtProperty -> declaration.initializer
|
||||||
|
is KtDestructuringDeclaration -> declaration.initializer
|
||||||
|
else -> null
|
||||||
|
} ?: return
|
||||||
|
runWriteAction { addTypeArgumentsIfNeeded(initializer, typeArgumentList) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editor != null && !replaceOccurrence) {
|
||||||
|
editor.caretModel.moveToOffset(declaration.endOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
physicalExpression.chooseApplicableComponentFunctionsForVariableDeclaration(replaceOccurrence, editor) { componentFunctions ->
|
physicalExpression.chooseApplicableComponentFunctionsForVariableDeclaration(replaceOccurrence, editor) { componentFunctions ->
|
||||||
val validator = NewDeclarationNameValidator(
|
val validator = NewDeclarationNameValidator(
|
||||||
commonContainer,
|
commonContainer,
|
||||||
|
|||||||
+7
-1
@@ -155,6 +155,12 @@ class KotlinVariableInplaceIntroducer(
|
|||||||
it.replace(replacement)
|
it.replace(replacement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
postProcess(addedVariable)
|
}
|
||||||
|
|
||||||
|
override fun moveOffsetAfter(success: Boolean) {
|
||||||
|
super.moveOffsetAfter(success)
|
||||||
|
if (success) {
|
||||||
|
postProcess(addedVariable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user