From eb35827e9a9e8c9e07ee5bef8948c408e7c6f847 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 18 Dec 2014 19:00:48 +0300 Subject: [PATCH] More clear code --- .../KotlinCodeBlockSelectioner.kt | 20 ++++++++++--------- .../KotlinWordSelectionFilter.kt | 7 +++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinCodeBlockSelectioner.kt b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinCodeBlockSelectioner.kt index 1a9c59f0cb6..f7ab10cfb43 100644 --- a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinCodeBlockSelectioner.kt +++ b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinCodeBlockSelectioner.kt @@ -42,32 +42,34 @@ public class KotlinCodeBlockSelectioner : ExtendWordSelectionHandlerBase() { val node = e.getNode()!! val start = findBlockContentStart(node) - val end = findBlockContentEnd(node, start) + val end = findBlockContentEnd(node) + if (end > start) { + result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(start, end))) + } - result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(start, end))) result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, e.getTextRange()!!)) return result } - private fun findBlockContentStart(parentNode: ASTNode): Int { - val node = parentNode.getChildren(null) + private fun findBlockContentStart(blockNode: ASTNode): Int { + val node = blockNode.getChildren(null) .stream() .dropWhile { it.getElementType() != JetTokens.LBRACE } // search for '{' .drop(1) // skip it .dropWhile { it is PsiWhiteSpace } // and skip all whitespaces - .firstOrNull() ?: parentNode + .firstOrNull() ?: blockNode return node.getTextRange()!!.getStartOffset() } - private fun findBlockContentEnd(parentNode: ASTNode, startOffset: Int): Int { - val node = parentNode.getChildren(null) + private fun findBlockContentEnd(blockNode: ASTNode): Int { + val node = blockNode.getChildren(null) .reverse() .stream() .dropWhile { it.getElementType() != JetTokens.RBRACE } // search for '}' .drop(1) // skip it - .dropWhile { it is PsiWhiteSpace && (it: PsiWhiteSpace).getTextRange()!!.getStartOffset() > startOffset } // and skip all whitespaces - .firstOrNull() ?: parentNode.getLastChildNode()!! + .dropWhile { it is PsiWhiteSpace } // and skip all whitespaces + .firstOrNull() ?: blockNode.getLastChildNode()!! return node.getTextRange()!!.getEndOffset() } } diff --git a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinWordSelectionFilter.kt b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinWordSelectionFilter.kt index db2badb6540..9b9c7f20e59 100644 --- a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinWordSelectionFilter.kt +++ b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinWordSelectionFilter.kt @@ -21,16 +21,15 @@ import com.intellij.psi.PsiElement import org.jetbrains.jet.JetNodeTypes.* import org.jetbrains.jet.lang.psi.JetContainerNode import org.jetbrains.jet.lang.psi.JetElement +import org.jetbrains.jet.plugin.JetLanguage public class KotlinWordSelectionFilter : Condition{ override fun value(e: PsiElement): Boolean { + if (e.getLanguage() != JetLanguage.INSTANCE) return true 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 + if (e.getParent().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