Expand selection for class members #KT-28289 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-11-22 11:54:36 +09:00
committed by Alexander Podkhalyuzin
parent 736818dfa7
commit 7bf51f1533
35 changed files with 449 additions and 0 deletions
@@ -593,6 +593,7 @@
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinSuperTypeSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinBracketsSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinLabeledReturnSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinClassMemberSelectioner"/>
<basicWordSelectionFilter implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinWordSelectionFilter"/>
<typedHandler implementation="org.jetbrains.kotlin.idea.editor.KotlinTypedHandler"/>
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.editor.wordSelection
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtClassBody
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
class KotlinClassMemberSelectioner : ExtendWordSelectionHandlerBase() {
override fun canSelect(e: PsiElement): Boolean {
return e.parent is KtClassBody
}
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
val parent = e.parent
val firstChild = parent.firstChild ?: return null
val lastChild = parent.lastChild ?: return null
val startElement = firstChild.getNextSiblingIgnoringWhitespace() ?: firstChild
val endElement = lastChild.getPrevSiblingIgnoringWhitespace() ?: lastChild
val textRange = TextRange(startElement.textRange.startOffset, endElement.textRange.endOffset)
return expandToWholeLinesWithBlanks(editorText, textRange)
}
}
+12
View File
@@ -0,0 +1,12 @@
class C {
<caret>constructor()
init {
}
fun foo() {
}
// comment
val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
<selection><caret>constructor</selection>()
init {
}
fun foo() {
}
// comment
val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
<selection><caret>constructor()</selection>
init {
}
fun foo() {
}
// comment
val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
<selection> <caret>constructor()
</selection>
init {
}
fun foo() {
}
// comment
val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
<selection> <caret>constructor()
init {
}
fun foo() {
}
// comment
val bar = 1
</selection>}
+12
View File
@@ -0,0 +1,12 @@
class C <selection>{
<caret>constructor()
init {
}
fun foo() {
}
// comment
val bar = 1
}</selection>
+13
View File
@@ -0,0 +1,13 @@
class C {
constructor()
<caret>init {
}
fun foo() {
}
// comment
val bar = 1
}
+13
View File
@@ -0,0 +1,13 @@
class C {
constructor()
<selection><caret>init</selection> {
}
fun foo() {
}
// comment
val bar = 1
}
+13
View File
@@ -0,0 +1,13 @@
class C {
constructor()
<selection> <caret>init {
}
</selection>
fun foo() {
}
// comment
val bar = 1
}
+13
View File
@@ -0,0 +1,13 @@
class C {
<selection> constructor()
<caret>init {
}
fun foo() {
}
// comment
val bar = 1
</selection>}
+13
View File
@@ -0,0 +1,13 @@
class C {
<selection>
constructor()
<caret>init {
}
fun foo() {
}
// comment
val bar = 1
</selection>}
+13
View File
@@ -0,0 +1,13 @@
class C <selection>{
constructor()
<caret>init {
}
fun foo() {
}
// comment
val bar = 1
}</selection>
+13
View File
@@ -0,0 +1,13 @@
class C {
constructor()
init {
}
<caret>fun foo() {
}
// comment
val bar = 1
}
+13
View File
@@ -0,0 +1,13 @@
class C {
constructor()
init {
}
<selection><caret>fun</selection> foo() {
}
// comment
val bar = 1
}
+13
View File
@@ -0,0 +1,13 @@
class C {
constructor()
init {
}
<selection> <caret>fun foo() {
}
</selection>
// comment
val bar = 1
}
+13
View File
@@ -0,0 +1,13 @@
class C {
<selection> constructor()
init {
}
<caret>fun foo() {
}
// comment
val bar = 1
</selection>
}
+13
View File
@@ -0,0 +1,13 @@
class C {
<selection> constructor()
init {
}
<caret>fun foo() {
}
// comment
val bar = 1
</selection>}
+13
View File
@@ -0,0 +1,13 @@
class C <selection>{
constructor()
init {
}
<caret>fun foo() {
}
// comment
val bar = 1
}</selection>
+14
View File
@@ -0,0 +1,14 @@
class C {
constructor()
init {
}
fun foo() {
}
// comment
<caret>val bar = 1
}
+14
View File
@@ -0,0 +1,14 @@
class C {
constructor()
init {
}
fun foo() {
}
// comment
<selection><caret>val</selection> bar = 1
}
+14
View File
@@ -0,0 +1,14 @@
class C {
constructor()
init {
}
fun foo() {
}
// comment
<selection><caret>val bar = 1</selection>
}
+14
View File
@@ -0,0 +1,14 @@
class C {
constructor()
init {
}
fun foo() {
}
// comment
<selection> <caret>val bar = 1
</selection>
}
+14
View File
@@ -0,0 +1,14 @@
class C {
constructor()
init {
}
fun foo() {
}
<selection> // comment
<caret>val bar = 1
</selection>
}
+14
View File
@@ -0,0 +1,14 @@
class C {
<selection> constructor()
init {
}
fun foo() {
}
// comment
<caret>val bar = 1
</selection>
}
+14
View File
@@ -0,0 +1,14 @@
class C {
<selection> constructor()
init {
}
fun foo() {
}
// comment
<caret>val bar = 1
</selection>}
+14
View File
@@ -0,0 +1,14 @@
class C <selection>{
constructor()
init {
}
fun foo() {
}
// comment
<caret>val bar = 1
}</selection>
+12
View File
@@ -0,0 +1,12 @@
class C {
constructor()
init {
}
fun foo() {
}
<caret>// comment
val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
constructor()
init {
}
fun foo() {
}
<selection><caret>// comment</selection>
val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
constructor()
init {
}
fun foo() {
}
<selection> <caret>// comment
</selection> val bar = 1
}
+12
View File
@@ -0,0 +1,12 @@
class C {
constructor()
init {
}
fun foo() {
}
<selection> <caret>// comment
val bar = 1
</selection>}
+12
View File
@@ -0,0 +1,12 @@
class C {
<selection> constructor()
init {
}
fun foo() {
}
<caret>// comment
val bar = 1
</selection>}
+12
View File
@@ -0,0 +1,12 @@
class C <selection>{
constructor()
init {
}
fun foo() {
}
<caret>// comment
val bar = 1
}</selection>
@@ -135,6 +135,12 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
public void testLabeledReturn() { doTest(); }
public void testClassMember1() { doTest(); }
public void testClassMember2() { doTest(); }
public void testClassMember3() { doTest(); }
public void testClassMember4() { doTest(); }
public void testClassMember5() { doTest(); }
private void doTest() {
String dirName = getTestName(false);