KT-5896 Select Word should always have step for selecting the content of string literal
#KT-5896 Fixed
This commit is contained in:
@@ -321,6 +321,7 @@
|
|||||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinDocCommentSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinDocCommentSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinDeclarationSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinDeclarationSelectioner"/>
|
||||||
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinListSelectioner"/>
|
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinListSelectioner"/>
|
||||||
|
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinStringLiteralSelectioner"/>
|
||||||
<basicWordSelectionFilter implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinWordSelectionFilter"/>
|
<basicWordSelectionFilter implementation="org.jetbrains.jet.plugin.editor.wordSelection.KotlinWordSelectionFilter"/>
|
||||||
|
|
||||||
<typedHandler implementation="org.jetbrains.jet.plugin.editor.KotlinTypedHandler"/>
|
<typedHandler implementation="org.jetbrains.jet.plugin.editor.KotlinTypedHandler"/>
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.editor.wordSelection
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import org.jetbrains.jet.lang.psi.JetStringTemplateExpression
|
||||||
|
|
||||||
|
public class KotlinStringLiteralSelectioner : ExtendWordSelectionHandlerBase() {
|
||||||
|
override fun canSelect(e: PsiElement) = e is JetStringTemplateExpression
|
||||||
|
|
||||||
|
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
|
||||||
|
val entries = (e as JetStringTemplateExpression).getEntries()
|
||||||
|
if (entries.isEmpty()) return null
|
||||||
|
val start = entries.first().getTextRange().getStartOffset()
|
||||||
|
val end = entries.last().getTextRange().getEndOffset()
|
||||||
|
return listOf(TextRange(start, end))
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
-3
@@ -18,10 +18,23 @@ package org.jetbrains.jet.plugin.editor.wordSelection
|
|||||||
|
|
||||||
import com.intellij.openapi.util.Condition
|
import com.intellij.openapi.util.Condition
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
import org.jetbrains.jet.JetNodeTypes.*
|
||||||
import org.jetbrains.jet.lang.psi.JetContainerNode
|
import org.jetbrains.jet.lang.psi.JetContainerNode
|
||||||
|
import org.jetbrains.jet.lang.psi.JetElement
|
||||||
|
|
||||||
public class KotlinWordSelectionFilter : Condition<PsiElement>{
|
public class KotlinWordSelectionFilter : Condition<PsiElement>{
|
||||||
override fun value(e: PsiElement)
|
override fun value(e: PsiElement): Boolean {
|
||||||
= !KotlinListSelectioner.canSelect(e) && e !is JetBlockExpression && e !is JetContainerNode
|
|
||||||
|
if (KotlinListSelectioner.canSelect(e)) return false
|
||||||
|
if (e is JetContainerNode) return false
|
||||||
|
|
||||||
|
val parent = e.getParent()
|
||||||
|
if (parent !is JetElement) return true
|
||||||
|
if (parent.getFirstChild().getNextSibling() == null) return false // skip nodes with the same range as their parent
|
||||||
|
|
||||||
|
return when (e.getNode().getElementType()) {
|
||||||
|
BLOCK, LITERAL_STRING_TEMPLATE_ENTRY -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa <caret>bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa <selection><caret>bbb</selection>"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "<selection>aaa <caret>bbb</selection>"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = <selection>"aaa <caret>bbb"</selection>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa $x <caret>bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa $x <selection><caret>bbb</selection>"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "<selection>aaa $x <caret>bbb</selection>"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = <selection>"aaa $x <caret>bbb"</selection>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa $<caret>x bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa $<selection><caret>x</selection> bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa <selection>$<caret>x</selection> bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "<selection>aaa $<caret>x bbb</selection>"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = <selection>"aaa $<caret>x bbb"</selection>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa ${<caret>x + y} bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa ${<selection><caret>x</selection> + y} bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa ${<selection><caret>x + y</selection>} bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "aaa <selection>${<caret>x + y}</selection> bbb"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = "<selection>aaa ${<caret>x + y} bbb</selection>"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val v = <selection>"aaa ${<caret>x + y} bbb"</selection>
|
||||||
@@ -49,6 +49,12 @@ public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
|
|
||||||
public void testCommentForStatements() { doTest(); }
|
public void testCommentForStatements() { doTest(); }
|
||||||
|
|
||||||
|
public void testSimpleStringLiteral() { doTest(); }
|
||||||
|
|
||||||
|
public void testTemplateStringLiteral1() { doTest(); }
|
||||||
|
public void testTemplateStringLiteral2() { doTest(); }
|
||||||
|
public void testTemplateStringLiteral3() { doTest(); }
|
||||||
|
|
||||||
private void doTest() {
|
private void doTest() {
|
||||||
String dirName = getTestName(false);
|
String dirName = getTestName(false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user