Search in sources :

Example 71 with EditorEx

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) PsiFile(com.intellij.psi.PsiFile) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 72 with EditorEx

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Editor(com.intellij.openapi.editor.Editor) IdeView(com.intellij.ide.IdeView) Caret(com.intellij.openapi.editor.Caret) InjectedCaret(com.intellij.injected.editor.InjectedCaret) EditorWindow(com.intellij.injected.editor.EditorWindow) Nullable(org.jetbrains.annotations.Nullable)

Example 73 with EditorEx

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;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) FileType(com.intellij.openapi.fileTypes.FileType)

Example 74 with EditorEx

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;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) SettingsImpl(com.intellij.openapi.editor.impl.SettingsImpl) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with EditorEx

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;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorCustomization(com.intellij.ui.EditorCustomization)

Aggregations

EditorEx (com.intellij.openapi.editor.ex.EditorEx)153 Editor (com.intellij.openapi.editor.Editor)32 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)32 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)28 NotNull (org.jetbrains.annotations.NotNull)23 Document (com.intellij.openapi.editor.Document)22 EditorFactory (com.intellij.openapi.editor.EditorFactory)11 Nullable (org.jetbrains.annotations.Nullable)11 TextRange (com.intellij.openapi.util.TextRange)10 Project (com.intellij.openapi.project.Project)9 IElementType (com.intellij.psi.tree.IElementType)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)7 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 PsiFile (com.intellij.psi.PsiFile)7 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)6 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)6 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)6 FileType (com.intellij.openapi.fileTypes.FileType)6 Language (com.intellij.lang.Language)5