mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] select multi-line string content without line feeds
This commit is contained in:
+11
-19
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 <caret>ahc
|
||||
'''
|
||||
""", """
|
||||
print '''
|
||||
<selection> abc cde
|
||||
xyz <caret>ahc
|
||||
</selection> '''
|
||||
""")
|
||||
|
||||
doTestForSelectWord(3, """
|
||||
print '''
|
||||
abc cde
|
||||
xyz <caret>ahc
|
||||
'''
|
||||
""", """
|
||||
print '''<selection>
|
||||
abc cde
|
||||
xyz <caret>ahc
|
||||
</selection>'''
|
||||
""")
|
||||
|
||||
}
|
||||
|
||||
private void doTestForSelectWord(int count, String input, String expected) {
|
||||
myFixture.configureByText("a.groovy", input)
|
||||
selectWord(count)
|
||||
|
||||
Reference in New Issue
Block a user