From 11a72632bcec533c9bea86e49ce2e30723dc4076 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 15 Dec 2014 20:24:47 -0700 Subject: [PATCH] KT-3949 Extend selection in case of comment before several statements #KT-3949 Fixed --- .../wordSelection/KotlinStatementGroupSelectioner.kt | 5 ++--- idea/testData/wordSelection/CommentForStatements/0.kt | 9 +++++++++ idea/testData/wordSelection/CommentForStatements/1.kt | 9 +++++++++ idea/testData/wordSelection/CommentForStatements/2.kt | 9 +++++++++ idea/testData/wordSelection/CommentForStatements/3.kt | 9 +++++++++ idea/testData/wordSelection/CommentForStatements/4.kt | 9 +++++++++ idea/testData/wordSelection/CommentForStatements/5.kt | 9 +++++++++ idea/testData/wordSelection/CommentForStatements/6.kt | 9 +++++++++ .../org/jetbrains/jet/plugin/WordSelectionTest.java | 2 ++ 9 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 idea/testData/wordSelection/CommentForStatements/0.kt create mode 100644 idea/testData/wordSelection/CommentForStatements/1.kt create mode 100644 idea/testData/wordSelection/CommentForStatements/2.kt create mode 100644 idea/testData/wordSelection/CommentForStatements/3.kt create mode 100644 idea/testData/wordSelection/CommentForStatements/4.kt create mode 100644 idea/testData/wordSelection/CommentForStatements/5.kt create mode 100644 idea/testData/wordSelection/CommentForStatements/6.kt diff --git a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinStatementGroupSelectioner.kt b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinStatementGroupSelectioner.kt index d73c17b7df9..c8930b01737 100644 --- a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinStatementGroupSelectioner.kt +++ b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinStatementGroupSelectioner.kt @@ -16,10 +16,8 @@ package org.jetbrains.jet.plugin.editor.wordSelection -import com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange -import com.intellij.openapi.util.text.LineTokenizer import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.tree.LeafPsiElement @@ -31,13 +29,14 @@ import org.jetbrains.jet.lexer.JetTokens import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase import org.jetbrains.jet.lang.psi.psiUtil.siblings +import com.intellij.psi.PsiComment /** * Originally from IDEA platform: StatementGroupSelectioner */ public class KotlinStatementGroupSelectioner : ExtendWordSelectionHandlerBase() { override fun canSelect(e: PsiElement) - = e is JetExpression || e is JetWhenEntry + = e is JetExpression || e is JetWhenEntry || e is PsiComment override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? { val parent = e.getParent() diff --git a/idea/testData/wordSelection/CommentForStatements/0.kt b/idea/testData/wordSelection/CommentForStatements/0.kt new file mode 100644 index 00000000000..1c91711cf75 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/0.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatements/1.kt b/idea/testData/wordSelection/CommentForStatements/1.kt new file mode 100644 index 00000000000..952a6c1e447 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/1.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatements/2.kt b/idea/testData/wordSelection/CommentForStatements/2.kt new file mode 100644 index 00000000000..758ca6fb418 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/2.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatements/3.kt b/idea/testData/wordSelection/CommentForStatements/3.kt new file mode 100644 index 00000000000..27dd4110623 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/3.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatements/4.kt b/idea/testData/wordSelection/CommentForStatements/4.kt new file mode 100644 index 00000000000..90e2ecf1e53 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/4.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatements/5.kt b/idea/testData/wordSelection/CommentForStatements/5.kt new file mode 100644 index 00000000000..907e781dcc9 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/5.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/testData/wordSelection/CommentForStatements/6.kt b/idea/testData/wordSelection/CommentForStatements/6.kt new file mode 100644 index 00000000000..7755a7e2271 --- /dev/null +++ b/idea/testData/wordSelection/CommentForStatements/6.kt @@ -0,0 +1,9 @@ +fun test() { + x() + + // comment for several lines + foo() + bar() + + y() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java b/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java index 968463acddf..2e6dbec7760 100644 --- a/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java @@ -47,6 +47,8 @@ public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase { public void testIfBody() { doTest(); } + public void testCommentForStatements() { doTest(); } + private void doTest() { String dirName = getTestName(false);