From df28d34f0fc1ddcbce856b636843067ccfa16dec Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sun, 6 Sep 2015 02:08:24 +0300 Subject: [PATCH] Ctrl-W works badly for selecting body of multi-line lambda starting with comment (KT-9014) #KT-9014 Fixed --- .../wordSelection/KotlinStatementGroupSelectioner.kt | 7 ++----- .../wordSelection/CommentForStatementsInLambda/0.kt | 7 +++++++ .../wordSelection/CommentForStatementsInLambda/1.kt | 7 +++++++ .../wordSelection/CommentForStatementsInLambda/2.kt | 7 +++++++ .../wordSelection/CommentForStatementsInLambda/3.kt | 7 +++++++ .../wordSelection/CommentForStatementsInLambda/4.kt | 7 +++++++ .../wordSelection/CommentForStatementsInLambda/5.kt | 7 +++++++ .../wordSelection/CommentForStatementsInLambda/6.kt | 7 +++++++ .../tests/org/jetbrains/kotlin/idea/WordSelectionTest.java | 2 ++ 9 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/0.kt create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/1.kt create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/2.kt create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/3.kt create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/4.kt create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/5.kt create mode 100644 idea/testData/wordSelection/CommentForStatementsInLambda/6.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 b941abd0085..8b259802abd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStatementGroupSelectioner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinStatementGroupSelectioner.kt @@ -21,15 +21,12 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.tree.LeafPsiElement -import org.jetbrains.kotlin.psi.JetBlockExpression -import org.jetbrains.kotlin.psi.JetExpression -import org.jetbrains.kotlin.psi.JetWhenEntry -import org.jetbrains.kotlin.psi.JetWhenExpression import org.jetbrains.kotlin.lexer.JetTokens import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase import org.jetbrains.kotlin.psi.psiUtil.siblings import com.intellij.psi.PsiComment +import org.jetbrains.kotlin.psi.* /** * Originally from IDEA platform: StatementGroupSelectioner @@ -38,7 +35,7 @@ public class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() override fun canSelect(e: PsiElement): Boolean { if (e !is JetExpression && e !is JetWhenEntry && e !is PsiComment) return false val parent = e.getParent() - return parent is JetBlockExpression || parent is JetWhenExpression + return parent is JetBlockExpression || parent is JetWhenExpression || parent is JetFunctionLiteral } override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? { diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/0.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/0.kt new file mode 100644 index 00000000000..15bcdc09ee8 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/0.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 1 + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/1.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/1.kt new file mode 100644 index 00000000000..f944232af97 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/1.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 1 + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/2.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/2.kt new file mode 100644 index 00000000000..ff1d48713a1 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/2.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 1 + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/3.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/3.kt new file mode 100644 index 00000000000..82695e25714 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/3.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 1 + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/4.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/4.kt new file mode 100644 index 00000000000..b6d36da2c66 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/4.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 1 + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/5.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/5.kt new file mode 100644 index 00000000000..72977b3970e --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/5.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 1 + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatementsInLambda/6.kt b/idea/testData/wordSelection/CommentForStatementsInLambda/6.kt new file mode 100644 index 00000000000..6c43a684fc8 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatementsInLambda/6.kt @@ -0,0 +1,7 @@ +fun run(f: () -> Unit) = 1 +fun test() { + run { + // test + 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 fd812a74350..5c7ea475166 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -59,6 +59,8 @@ public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase { public void testCommentForStatements() { doTest(); } + public void testCommentForStatementsInLambda() { doTest(); } + public void testSimpleStringLiteral() { doTest(); } public void testSimpleStringLiteral2() { doTest(); }