From 7890658a9033b2dd38e9239e6c0d5e60c0263afa Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Tue, 24 Jul 2018 12:05:28 +0300 Subject: [PATCH] [groovy] select multi-line string content without line feeds --- .../selection/GroovyLiteralSelectioner.java | 30 +++++-------- .../plugins/groovy/GroovyActionsTest.groovy | 43 ++++++++++++------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java index b1434459de7f..10ab6fcffc64 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-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. - */ +// Copyright 2000-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 file. package org.jetbrains.plugins.groovy.editor.selection; @@ -52,13 +38,16 @@ public class GroovyLiteralSelectioner extends ExtendWordSelectionHandlerBase { if (e instanceof GrListOrMap) return result; + assert result != null; + int startOffset = -1; int endOffset = -1; final String text = e.getText(); final int stringOffset = e.getTextOffset(); final IElementType elementType = e.getNode().getElementType(); - if (elementType == GroovyTokenTypes.mGSTRING_CONTENT || elementType == GroovyTokenTypes.mREGEX_CONTENT || elementType == - GroovyTokenTypes.mDOLLAR_SLASH_REGEX_CONTENT) { + if (elementType == GroovyTokenTypes.mGSTRING_CONTENT || + elementType == GroovyTokenTypes.mREGEX_CONTENT || + elementType == GroovyTokenTypes.mDOLLAR_SLASH_REGEX_CONTENT) { int cur; int index = -1; while (true) { @@ -82,8 +71,11 @@ public class GroovyLiteralSelectioner extends ExtendWordSelectionHandlerBase { final String content = GrStringUtil.removeQuotes(text); - final int offset = stringOffset + text.indexOf(content); - result.add(new TextRange(offset, offset + content.length())); + String trimmedContent = content.trim(); + result.addAll(expandToWholeLine(editorText, TextRange.from(stringOffset + text.indexOf(trimmedContent), trimmedContent.length()))); + + result.add(TextRange.from(stringOffset + text.indexOf(content), content.length())); + return result; } } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy index 6f41ee80020d..6db98e34f24e 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-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 file. package org.jetbrains.plugins.groovy import com.intellij.openapi.actionSystem.IdeActions @@ -225,6 +211,33 @@ class A { ''') } + void testMultiLineStingSelection() { + doTestForSelectWord(2, """ + print ''' + abc cde + xyz ahc + ''' + """, """ + print ''' + abc cde + xyz ahc + ''' + """) + + doTestForSelectWord(3, """ + print ''' + abc cde + xyz ahc + ''' + """, """ + print ''' + abc cde + xyz ahc + ''' + """) + + } + private void doTestForSelectWord(int count, String input, String expected) { myFixture.configureByText("a.groovy", input) selectWord(count)