use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class JavaSurroundWithTest method doTest.
private void doTest(@NotNull String fileName, Surrounder surrounder) {
configureByFile(BASE_PATH + fileName + ".java");
SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE));
assertNotNull(item);
SelectionModel selectionModel = getEditor().getSelectionModel();
PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
assertTrue(surrounder.isApplicable(elements));
SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder);
checkResultByFile(BASE_PATH + fileName + "_after.java");
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class JavaSurroundWithTest method testNoParenthesisSurrounderForLambdaParameter.
public void testNoParenthesisSurrounderForLambdaParameter() {
configureByFile(BASE_PATH + getTestName(false) + ".java");
SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE));
assertNotNull(item);
SelectionModel selectionModel = getEditor().getSelectionModel();
PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
assertEmpty(elements);
}
use of com.intellij.openapi.editor.SelectionModel in project Intellij-Plugin by getgauge.
the class StepsBuilder method getPsiElements.
protected List<PsiElement> getPsiElements(Class stepClass) {
SelectionModel selectionModel = editor.getSelectionModel();
List<PsiElement> specSteps = new ArrayList<>();
int currentOffset = selectionModel.getSelectionStart();
while (selectionModel.getSelectionEnd() >= currentOffset) {
try {
if (psiFile.getText().charAt(currentOffset++) == '\n')
continue;
PsiElement step = getStep(psiFile.findElementAt(currentOffset), stepClass);
if (step == null)
return new ArrayList<>();
specSteps.add(step);
currentOffset += step.getText().length();
} catch (Exception ignored) {
}
}
return specSteps;
}
use of com.intellij.openapi.editor.SelectionModel in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCodeInsightFixtureTestCase method findElementAtCaretOrInSelection.
@NotNull
protected PsiElement findElementAtCaretOrInSelection() {
SelectionModel selectionModel = myFixture.getEditor().getSelectionModel();
if (selectionModel.hasSelection()) {
PsiElement left = myFixture.getFile().findElementAt(selectionModel.getSelectionStart());
PsiElement right = myFixture.getFile().findElementAt(selectionModel.getSelectionEnd() - 1);
assertNotNull(left);
assertNotNull(right);
return ObjectUtils.assertNotNull(PsiTreeUtil.findCommonParent(left, right));
} else {
return ObjectUtils.assertNotNull(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()));
}
}
use of com.intellij.openapi.editor.SelectionModel in project buck by facebook.
the class BuckCopyPasteProcessor method preprocessOnPaste.
@Override
public String preprocessOnPaste(Project project, PsiFile psiFile, Editor editor, String text, RawText rawText) {
if (!(psiFile instanceof BuckFile)) {
return text;
}
final Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).commitDocument(document);
final SelectionModel selectionModel = editor.getSelectionModel();
// Pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor.
final int selectionStart = selectionModel.getSelectionStart();
final PsiElement element = psiFile.findElementAt(selectionStart);
if (element == null) {
return text;
}
if (BuckPsiUtils.hasElementType(element.getNode(), TokenType.WHITE_SPACE, BuckTypes.SINGLE_QUOTED_STRING, BuckTypes.DOUBLE_QUOTED_STRING)) {
PsiElement property = BuckPsiUtils.findAncestorWithType(element, BuckTypes.PROPERTY);
if (checkPropertyName(property)) {
return formatPasteText(text, element, project);
}
}
return text;
}
Aggregations