From 730f0bdcab0d58529fcbfb5da455d50d2dc55ad1 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 13 May 2024 18:28:31 +0200 Subject: [PATCH] [kotlin] extract function: keep selection range as narrow as possible ^KTIJ-29938 fixed GitOrigin-RevId: 5302707448930515842bf6e17b6e2f10f5e92fb0 --- .../DontSkipWhitespacesBefore.after.kt | 8 ++++++++ .../extractFunctionInplace/DontSkipWhitespacesBefore.kt | 4 ++++ .../extractFunction/AbstractInplaceExtractionHelper.kt | 3 ++- .../introduce/FirInplaceExtractFunctionTest.kt | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.after.kt create mode 100644 plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.after.kt new file mode 100644 index 000000000000..487072c408af --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.after.kt @@ -0,0 +1,8 @@ +fun testFun(x: Any): Unit { + println(x) + extracted() +} + +private fun extracted() { + println("that's something else") +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt new file mode 100644 index 000000000000..a932d2d6fae4 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt @@ -0,0 +1,4 @@ +fun testFun(x: Any): Unit { + println(x) + println("that's something else") +} \ No newline at end of file diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/AbstractInplaceExtractionHelper.kt b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/AbstractInplaceExtractionHelper.kt index 4de6fa169bfc..51a5dcb7553d 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/AbstractInplaceExtractionHelper.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/AbstractInplaceExtractionHelper.kt @@ -11,6 +11,7 @@ import com.intellij.openapi.keymap.KeymapUtil import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.SmartPointerManager import com.intellij.psi.util.PsiTreeUtil @@ -61,7 +62,7 @@ interface AbstractInplaceExtractionHelper