use of com.intellij.openapi.editor.ex.EditorEx 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.ex.EditorEx in project intellij-community by JetBrains.
the class TextEditorPsiDataProvider method getData.
@Override
@Nullable
public Object getData(@NotNull final String dataId, @NotNull final Editor e, @NotNull final Caret caret) {
if (e.isDisposed() || !(e instanceof EditorEx)) {
return null;
}
VirtualFile file = ((EditorEx) e).getVirtualFile();
if (file == null || !file.isValid())
return null;
Project project = e.getProject();
if (dataId.equals(injectedId(EDITOR.getName()))) {
if (project == null || PsiDocumentManager.getInstance(project).isUncommited(e.getDocument())) {
return e;
} else {
return InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(e, caret, getPsiFile(e, file));
}
}
if (HOST_EDITOR.is(dataId)) {
return e instanceof EditorWindow ? ((EditorWindow) e).getDelegate() : e;
}
if (CARET.is(dataId)) {
return caret;
}
if (dataId.equals(injectedId(CARET.getName()))) {
Editor editor = (Editor) getData(injectedId(EDITOR.getName()), e, caret);
assert editor != null;
return getInjectedCaret(editor, caret);
}
if (dataId.equals(injectedId(PSI_ELEMENT.getName()))) {
Editor editor = (Editor) getData(injectedId(EDITOR.getName()), e, caret);
assert editor != null;
Caret injectedCaret = getInjectedCaret(editor, caret);
return getPsiElementIn(editor, injectedCaret, file);
}
if (PSI_ELEMENT.is(dataId)) {
return getPsiElementIn(e, caret, file);
}
if (dataId.equals(injectedId(LANGUAGE.getName()))) {
PsiFile psiFile = (PsiFile) getData(injectedId(PSI_FILE.getName()), e, caret);
Editor editor = (Editor) getData(injectedId(EDITOR.getName()), e, caret);
if (psiFile == null || editor == null)
return null;
Caret injectedCaret = getInjectedCaret(editor, caret);
return getLanguageAtCurrentPositionInEditor(injectedCaret, psiFile);
}
if (LANGUAGE.is(dataId)) {
final PsiFile psiFile = getPsiFile(e, file);
if (psiFile == null)
return null;
return getLanguageAtCurrentPositionInEditor(caret, psiFile);
}
if (dataId.equals(injectedId(VIRTUAL_FILE.getName()))) {
PsiFile psiFile = (PsiFile) getData(injectedId(PSI_FILE.getName()), e, caret);
if (psiFile == null)
return null;
return psiFile.getVirtualFile();
}
if (dataId.equals(injectedId(PSI_FILE.getName()))) {
Editor editor = (Editor) getData(injectedId(EDITOR.getName()), e, caret);
if (editor == null) {
return null;
}
if (project == null) {
return null;
}
return PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
}
if (PSI_FILE.is(dataId)) {
return getPsiFile(e, file);
}
if (IDE_VIEW.is(dataId)) {
final PsiFile psiFile = project == null ? null : PsiManager.getInstance(project).findFile(file);
final PsiDirectory psiDirectory = psiFile != null ? psiFile.getParent() : null;
if (psiDirectory != null && (psiDirectory.isPhysical() || ApplicationManager.getApplication().isUnitTestMode())) {
return new IdeView() {
@Override
public void selectElement(final PsiElement element) {
Editor editor = EditorHelper.openInEditor(element);
if (editor != null) {
ToolWindowManager.getInstance(element.getProject()).activateEditorComponent();
}
}
@NotNull
@Override
public PsiDirectory[] getDirectories() {
return new PsiDirectory[] { psiDirectory };
}
@Override
public PsiDirectory getOrChooseDirectory() {
return psiDirectory;
}
};
}
}
if (CONTEXT_LANGUAGES.is(dataId)) {
return computeLanguages(e, caret);
}
return null;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class LanguageTextField method createEditor.
@Override
protected EditorEx createEditor() {
final EditorEx ex = super.createEditor();
if (myLanguage != null) {
final FileType fileType = myLanguage.getAssociatedFileType();
ex.setHighlighter(HighlighterFactory.createHighlighter(myProject, fileType));
}
ex.setEmbeddedIntoDialogWrapper(true);
return ex;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class DetailViewImpl method createEditor.
@NotNull
protected Editor createEditor(@Nullable Project project, Document document, VirtualFile file) {
EditorEx editor = (EditorEx) EditorFactory.getInstance().createViewer(document, project);
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
editor.setFile(file);
editor.setHighlighter(highlighter);
EditorSettings settings = editor.getSettings();
settings.setAnimatedScrolling(false);
settings.setRefrainFromScrolling(false);
settings.setLineNumbersShown(true);
settings.setFoldingOutlineShown(false);
if (settings instanceof SettingsImpl) {
((SettingsImpl) settings).setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.PREVIEW);
}
editor.getFoldingModel().setFoldingEnabled(false);
return editor;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class TextFieldWithCompletion method createEditor.
@Override
protected EditorEx createEditor() {
EditorEx editor = super.createEditor();
EditorCustomization disableSpellChecking = SpellCheckingEditorCustomizationProvider.getInstance().getDisabledCustomization();
if (disableSpellChecking != null)
disableSpellChecking.customize(editor);
editor.putUserData(AutoPopupController.ALWAYS_AUTO_POPUP, myForceAutoPopup);
if (myShowHint) {
TextCompletionUtil.installCompletionHint(editor);
}
return editor;
}
Aggregations