Introduce Variable: Move caret to the end of declaration when replacing "statement" expression

#KT-10663 Fixed
This commit is contained in:
Alexey Sedunov
2016-01-14 14:17:35 +03:00
parent 16ab4bec34
commit 9081f5df52
2 changed files with 22 additions and 11 deletions
@@ -500,16 +500,6 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
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 allReplaces = when (replaceChoice) {
OccurrencesChooser.ReplaceChoice.ALL -> allOccurrences
@@ -525,6 +515,21 @@ object KotlinIntroduceVariableHandler : RefactoringActionHandler {
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 ->
val validator = NewDeclarationNameValidator(
commonContainer,
@@ -155,6 +155,12 @@ class KotlinVariableInplaceIntroducer(
it.replace(replacement)
}
}
postProcess(addedVariable)
}
override fun moveOffsetAfter(success: Boolean) {
super.moveOffsetAfter(success)
if (success) {
postProcess(addedVariable)
}
}
}