use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class TestEditorManagerImpl method openTextEditor.
@Override
public Editor openTextEditor(@NotNull OpenFileDescriptor descriptor, boolean focusEditor) {
final VirtualFile file = descriptor.getFile();
Editor editor = myVirtualFile2Editor.get(file);
if (editor == null) {
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
LOG.assertTrue(psiFile != null, file);
Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
LOG.assertTrue(document != null, psiFile);
editor = EditorFactory.getInstance().createEditor(document, myProject);
final EditorHighlighter highlighter = HighlighterFactory.createHighlighter(myProject, file);
((EditorEx) editor).setHighlighter(highlighter);
((EditorEx) editor).setFile(file);
myVirtualFile2Editor.put(file, editor);
}
if (descriptor.getOffset() >= 0) {
editor.getCaretModel().moveToOffset(descriptor.getOffset());
} else if (descriptor.getLine() >= 0 && descriptor.getColumn() >= 0) {
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(descriptor.getLine(), descriptor.getColumn()));
}
editor.getSelectionModel().removeSelection();
myActiveFile = file;
return editor;
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class NamedElementDuplicateHandler method executeWriteAction.
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
Project project = editor.getProject();
if (project != null && !editor.getSelectionModel().hasSelection()) {
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file != null) {
VisualPosition caret = editor.getCaretModel().getVisualPosition();
Pair<LogicalPosition, LogicalPosition> lines = EditorUtil.calcSurroundingRange(editor, caret, caret);
TextRange toDuplicate = new TextRange(editor.logicalPositionToOffset(lines.first), editor.logicalPositionToOffset(lines.second));
PsiElement name = findNameIdentifier(editor, file, toDuplicate);
if (name != null && !name.getTextRange().containsOffset(editor.getCaretModel().getOffset())) {
editor.getCaretModel().moveToOffset(name.getTextOffset());
}
}
}
myOriginal.execute(editor, dataContext);
}
use of com.intellij.openapi.editor.LogicalPosition in project android by JetBrains.
the class AndroidValueResourcesTest method testNavigationInPlatformXml3.
public void testNavigationInPlatformXml3() throws Exception {
VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
assertNotNull(themes_holo);
VirtualFile colors_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/colors_holo.xml").toString());
assertNotNull(colors_holo);
// In themes_holo.xml: point to value of "bright_foreground_holo_light" on line:
// <item name="colorForeground">@color/bright_foreground_holo_light</item>
// Goto action should navigate to "bright_foreground_holo_light" in colors_holo.xml, on line:
// <color name="bright_foreground_holo_light">@color/background_holo_dark</color>
myFixture.configureFromExistingVirtualFile(themes_holo);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(407, 60));
PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
assertEquals("bright_foreground_holo_light", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
assertEquals("color", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
assertEquals(colors_holo, targetElement.getContainingFile().getVirtualFile());
}
use of com.intellij.openapi.editor.LogicalPosition in project android by JetBrains.
the class EditorFixture method select.
/**
* Given a {@code regex} with one capturing group, selects the subsequence captured in the first match found in the selected text editor.
*
* @throws IllegalStateException if there is no currently selected text editor or no match is found
* @throws IllegalArgumentException if {@code regex} does not have exactly one capturing group
*/
@NotNull
public EditorFixture select(String regex) {
Matcher matcher = Pattern.compile(regex).matcher(getCurrentFileContents());
checkArgument(matcher.groupCount() == 1, "must have exactly one capturing group: %s", regex);
matcher.find();
int start = matcher.start(1);
int end = matcher.end(1);
SelectTarget selectTarget = GuiQuery.getNonNull(() -> {
Editor editor = FileEditorManager.getInstance(myFrame.getProject()).getSelectedTextEditor();
checkState(editor != null, "no currently selected text editor");
LogicalPosition startPosition = editor.offsetToLogicalPosition(start);
LogicalPosition endPosition = editor.offsetToLogicalPosition(end);
// CENTER_DOWN tries to make endPosition visible; if that fails, write selectWithKeyboard and rename this method selectWithMouse?
editor.getScrollingModel().scrollTo(startPosition, ScrollType.CENTER_DOWN);
SelectTarget target = new SelectTarget();
target.component = editor.getContentComponent();
target.startPoint = editor.logicalPositionToXY(startPosition);
target.endPoint = editor.logicalPositionToXY(endPosition);
return target;
});
robot.pressMouse(selectTarget.component, selectTarget.startPoint);
robot.moveMouse(selectTarget.component, selectTarget.endPoint);
robot.releaseMouseButtons();
return this;
}
use of com.intellij.openapi.editor.LogicalPosition in project android by JetBrains.
the class ConsoleHighlighter method appendToDocument.
private void appendToDocument() {
Document document = myEditor.getDocument();
if (document != null) {
String pendingString = StringUtil.convertLineSeparators(getPendingString());
document.insertString(document.getTextLength(), pendingString);
if (myEditor instanceof Editor) {
Editor editor = (Editor) myEditor;
int lineCount = document.getLineCount();
editor.getScrollingModel().scrollTo(new LogicalPosition(lineCount - 1, 0), ScrollType.MAKE_VISIBLE);
}
}
}
Aggregations