From 5aa0b7d2aaca26defb4c173c755ae02dd95b2a93 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 4 Apr 2018 07:12:43 +0300 Subject: [PATCH] Extend Selection: whole literal with braces is selected after parameters (KT-13420) #KT-13420 Fixed --- .../wordSelection/KotlinStatementGroupSelectioner.kt | 10 ++++------ .../wordSelection/ValueParametersInLambda/0.kt | 5 +++++ .../wordSelection/ValueParametersInLambda/1.kt | 5 +++++ .../wordSelection/ValueParametersInLambda/2.kt | 5 +++++ .../wordSelection/ValueParametersInLambda/3.kt | 5 +++++ .../org/jetbrains/kotlin/idea/WordSelectionTest.java | 2 ++ 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 idea/testData/wordSelection/ValueParametersInLambda/0.kt create mode 100644 idea/testData/wordSelection/ValueParametersInLambda/1.kt create mode 100644 idea/testData/wordSelection/ValueParametersInLambda/2.kt create mode 100644 idea/testData/wordSelection/ValueParametersInLambda/3.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStatementGroupSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStatementGroupSelectioner.kt index 7dd6f60d724..17510522788 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStatementGroupSelectioner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStatementGroupSelectioner.kt @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings */ class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() { override fun canSelect(e: PsiElement): Boolean { - if (e !is KtExpression && e !is KtWhenEntry && e !is PsiComment) return false + if (e !is KtExpression && e !is KtWhenEntry && e !is KtParameterList && e !is PsiComment) return false val parent = e.parent return parent is KtBlockExpression || parent is KtWhenExpression || parent is KtFunctionLiteral } @@ -43,8 +43,7 @@ class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() { val startElement = e.siblings(forward = false, withItself = false) .firstOrNull { // find preceding '{' or blank line - it is LeafPsiElement && it.elementType == KtTokens.LBRACE || - it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1 + it is LeafPsiElement && it.elementType == KtTokens.LBRACE || it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1 } ?.siblings(forward = true, withItself = false) ?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element after it @@ -53,14 +52,13 @@ class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() { val endElement = e.siblings(forward = true, withItself = false) .firstOrNull { // find next '}' or blank line - it is LeafPsiElement && it.elementType == KtTokens.RBRACE || - it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1 + it is LeafPsiElement && it.elementType == KtTokens.RBRACE || it is PsiWhiteSpace && it.getText()!!.count { it == '\n' } > 1 } ?.siblings(forward = false, withItself = false) ?.dropWhile { it is PsiWhiteSpace } // and take first non-whitespace element before it ?.firstOrNull() ?: parent.lastChild!! - return ExtendWordSelectionHandlerBase.expandToWholeLine( + return expandToWholeLine( editorText, TextRange( startElement.textRange!!.startOffset, diff --git a/idea/testData/wordSelection/ValueParametersInLambda/0.kt b/idea/testData/wordSelection/ValueParametersInLambda/0.kt new file mode 100644 index 00000000000..2bfecd8a67a --- /dev/null +++ b/idea/testData/wordSelection/ValueParametersInLambda/0.kt @@ -0,0 +1,5 @@ +fun foo(f: (Int) -> Int) {} + +fun test() { + foo { it -> it + 1 } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/ValueParametersInLambda/1.kt b/idea/testData/wordSelection/ValueParametersInLambda/1.kt new file mode 100644 index 00000000000..fe1bd46c123 --- /dev/null +++ b/idea/testData/wordSelection/ValueParametersInLambda/1.kt @@ -0,0 +1,5 @@ +fun foo(f: (Int) -> Int) {} + +fun test() { + foo { it -> it + 1 } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/ValueParametersInLambda/2.kt b/idea/testData/wordSelection/ValueParametersInLambda/2.kt new file mode 100644 index 00000000000..a7dbaa832e7 --- /dev/null +++ b/idea/testData/wordSelection/ValueParametersInLambda/2.kt @@ -0,0 +1,5 @@ +fun foo(f: (Int) -> Int) {} + +fun test() { + foo { it -> it + 1 } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/ValueParametersInLambda/3.kt b/idea/testData/wordSelection/ValueParametersInLambda/3.kt new file mode 100644 index 00000000000..a6d49448594 --- /dev/null +++ b/idea/testData/wordSelection/ValueParametersInLambda/3.kt @@ -0,0 +1,5 @@ +fun foo(f: (Int) -> Int) {} + +fun test() { + foo { it -> it + 1 } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java index 175083c88e3..aaeee33defb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -49,6 +49,8 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase { doTest(); } + public void testValueParametersInLambda() { doTest(); } + public void testDocComment() { doTest(); } public void testDocCommentOneLine() { doTest(); }