use of com.intellij.openapi.editor.CaretModel in project intellij-plugins by JetBrains.
the class FlexLiveTemplatesTest method testPublicFunctionWithTypingInMxml.
public void testPublicFunctionWithTypingInMxml() throws Exception {
doTest("pf", "mxml", segmentIndex -> {
final CaretModel caretModel = getEditor().getCaretModel();
switch(segmentIndex) {
case 0:
type("functionName");
caretModel.moveToOffset(caretModel.getOffset() + 1);
break;
case 1:
type("param:Object");
caretModel.moveToOffset(caretModel.getOffset() + 1);
break;
case 2:
type("String");
caretModel.moveToOffset(caretModel.getOffset() + 1);
break;
}
});
}
use of com.intellij.openapi.editor.CaretModel in project intellij-plugins by JetBrains.
the class DartIntroduceHandler method performAction.
public void performAction(DartIntroduceOperation operation) {
final PsiFile file = operation.getFile();
if (!CommonRefactoringUtil.checkReadOnlyStatus(file)) {
return;
}
final Editor editor = operation.getEditor();
if (editor.getSettings().isVariableInplaceRenameEnabled()) {
final TemplateState templateState = TemplateManagerImpl.getTemplateState(operation.getEditor());
if (templateState != null && !templateState.isFinished()) {
return;
}
}
PsiElement element1 = null;
PsiElement element2 = null;
final SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.hasSelection()) {
element1 = file.findElementAt(selectionModel.getSelectionStart());
element2 = file.findElementAt(selectionModel.getSelectionEnd() - 1);
if (element1 instanceof PsiWhiteSpace) {
int startOffset = element1.getTextRange().getEndOffset();
element1 = file.findElementAt(startOffset);
}
if (element2 instanceof PsiWhiteSpace) {
int endOffset = element2.getTextRange().getStartOffset();
element2 = file.findElementAt(endOffset - 1);
}
} else {
if (smartIntroduce(operation)) {
return;
}
final CaretModel caretModel = editor.getCaretModel();
final Document document = editor.getDocument();
int lineNumber = document.getLineNumber(caretModel.getOffset());
if ((lineNumber >= 0) && (lineNumber < document.getLineCount())) {
element1 = file.findElementAt(document.getLineStartOffset(lineNumber));
element2 = file.findElementAt(document.getLineEndOffset(lineNumber) - 1);
}
}
final Project project = operation.getProject();
if (element1 == null || element2 == null) {
showCannotPerformError(project, editor);
return;
}
element1 = DartRefactoringUtil.getSelectedExpression(project, file, element1, element2);
if (element1 == null) {
showCannotPerformError(project, editor);
return;
}
if (!checkIntroduceContext(file, editor, element1)) {
return;
}
operation.setElement(element1);
performActionOnElement(operation);
}
Aggregations