mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
brace matcher-based select word in custom file types (IDEA-117225)
This commit is contained in:
+3
-1
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.editorActions.wordSelection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -38,7 +39,8 @@ public class NaturalLanguageTextSelectioner extends ExtendWordSelectionHandlerBa
|
||||
|
||||
@Override
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof PsiPlainText || e instanceof PsiComment;
|
||||
return (e instanceof PsiPlainText || e instanceof PsiComment) &&
|
||||
!(e.getContainingFile().getFileType() instanceof CustomSyntaxTableFileType);
|
||||
}
|
||||
|
||||
private static TextRange findParagraphRange(String text, int start, int end) {
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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 com.intellij.ide.highlighter.custom.impl;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.BraceMatcherBasedSelectioner;
|
||||
import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class CustomFileTypeSelectWordHandler extends BraceMatcherBasedSelectioner {
|
||||
@Override
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e.getContainingFile().getFileType() instanceof CustomSyntaxTableFileType;
|
||||
}
|
||||
}
|
||||
@@ -563,6 +563,7 @@
|
||||
<extendWordSelectionHandler implementation="com.intellij.codeInsight.editorActions.wordSelection.NaturalLanguageTextSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="com.intellij.codeInsight.editorActions.wordSelection.WordSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="com.intellij.codeInsight.editorActions.wordSelection.LineCommentSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="com.intellij.ide.highlighter.custom.impl.CustomFileTypeSelectWordHandler"/>
|
||||
|
||||
<syntaxHighlighter factoryClass="com.intellij.ide.highlighter.custom.impl.CustomFileTypeHighlighterProvider"/>
|
||||
<fileTypeRegistrator implementation="com.intellij.ide.highlighter.custom.impl.StandardFileTypeRegistrator"/>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
x = foo[bar(<selection>xyzzy</selection> + fizzy)];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
x = foo[bar(<selection>xyzzy + fizzy</selection>)];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
x = foo[bar<selection>(xyzzy + fizzy)</selection>];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
x = foo[<selection>bar(xyzzy + fizzy)</selection>];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
x = foo<selection>[bar(xyzzy + fizzy)]</selection>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
<selection>x = foo[bar(xyzzy + fizzy)];</selection>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
<selection> x = foo[bar(xyzzy + fizzy)];</selection>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
<selection> x = foo[bar(xyzzy + fizzy)];
|
||||
</selection>}
|
||||
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
x = foo[bar(xy<caret>zzy + fizzy)];
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
if (!<selection>gets_s</selection>(buffer, sizeof(buffer)-1))
|
||||
@@ -0,0 +1 @@
|
||||
if (<selection>!gets_s(buffer, sizeof(buffer)-1)</selection>)
|
||||
@@ -0,0 +1 @@
|
||||
if (!gets<caret>_s(buffer, sizeof(buffer)-1))
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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 com.intellij.ide.highlighter.custom;
|
||||
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class CustomFileTypeWordSelectionTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
public CustomFileTypeWordSelectionTest() {
|
||||
PlatformTestCase.initPlatformLangPrefix();
|
||||
}
|
||||
|
||||
public void testCustomFileTypeBraces() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCustomFileTypeSkipMatchedPair() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/platform/platform-tests/testData/selectWord/";
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
CodeInsightTestUtil.doWordSelectionTestOnDirectory(myFixture, getTestName(true), "cs");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user