KT-3949 Extend selection in case of comment before several statements

#KT-3949 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-12-15 20:24:47 -07:00
parent 3059a46ca7
commit 11a72632bc
9 changed files with 67 additions and 3 deletions
@@ -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<TextRange>? {
val parent = e.getParent()
@@ -0,0 +1,9 @@
fun test() {
x()
// <caret>comment for several lines
foo()
bar()
y()
}
@@ -0,0 +1,9 @@
fun test() {
x()
// <selection><caret>comment</selection> for several lines
foo()
bar()
y()
}
@@ -0,0 +1,9 @@
fun test() {
x()
// <selection><caret>comment for several lines</selection>
foo()
bar()
y()
}
@@ -0,0 +1,9 @@
fun test() {
x()
<selection>// <caret>comment for several lines</selection>
foo()
bar()
y()
}
@@ -0,0 +1,9 @@
fun test() {
x()
<selection> // <caret>comment for several lines
</selection> foo()
bar()
y()
}
@@ -0,0 +1,9 @@
fun test() {
x()
<selection> // <caret>comment for several lines
foo()
bar()
</selection>
y()
}
@@ -0,0 +1,9 @@
fun test() {
<selection> x()
// <caret>comment for several lines
foo()
bar()
y()
</selection>}
@@ -47,6 +47,8 @@ public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase {
public void testIfBody() { doTest(); }
public void testCommentForStatements() { doTest(); }
private void doTest() {
String dirName = getTestName(false);