Search in sources :

Example 96 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class XmlTagRenameHandler method getElement.

@Nullable
private static PsiElement getElement(@Nullable final DataContext context) {
    if (context != null) {
        final Editor editor = getEditor(context);
        if (editor != null) {
            final int offset = editor.getCaretModel().getOffset();
            final PsiFile file = CommonDataKeys.PSI_FILE.getData(context);
            if (file instanceof XmlFile) {
                return file.getViewProvider().findElementAt(offset);
            }
            if (file != null) {
                final Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
                if (language != file.getLanguage()) {
                    final PsiFile psiAtOffset = file.getViewProvider().getPsi(language);
                    if (psiAtOffset instanceof XmlFile) {
                        return psiAtOffset.findElementAt(offset);
                    }
                }
            }
        }
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 97 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class AddDtdDeclarationFix method applyFix.

@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    final PsiFile containingFile = element.getContainingFile();
    @NonNls String prefixToInsert = "";
    @NonNls String suffixToInsert = "";
    final int UNDEFINED_OFFSET = -1;
    int anchorOffset = UNDEFINED_OFFSET;
    PsiElement anchor = PsiTreeUtil.getParentOfType(element, XmlElementDecl.class, XmlAttlistDecl.class, XmlEntityDecl.class, XmlConditionalSection.class);
    if (anchor != null)
        anchorOffset = anchor.getTextRange().getStartOffset();
    if (anchorOffset == UNDEFINED_OFFSET && containingFile.getLanguage() == XMLLanguage.INSTANCE) {
        XmlFile file = (XmlFile) containingFile;
        final XmlProlog prolog = file.getDocument().getProlog();
        assert prolog != null;
        final XmlDoctype doctype = prolog.getDoctype();
        final XmlMarkupDecl markupDecl;
        if (doctype != null) {
            markupDecl = doctype.getMarkupDecl();
        } else {
            markupDecl = null;
        }
        if (doctype == null) {
            final XmlTag rootTag = file.getDocument().getRootTag();
            prefixToInsert = "<!DOCTYPE " + ((rootTag != null) ? rootTag.getName() : "null");
            suffixToInsert = ">\n";
        }
        if (markupDecl == null) {
            prefixToInsert += " [\n";
            suffixToInsert = "]" + suffixToInsert;
            if (doctype != null) {
                // just before last '>'
                anchorOffset = doctype.getTextRange().getEndOffset() - 1;
            } else {
                anchorOffset = prolog.getTextRange().getEndOffset();
            }
        }
    }
    if (anchorOffset == UNDEFINED_OFFSET)
        anchorOffset = element.getTextRange().getStartOffset();
    OpenFileDescriptor openDescriptor = new OpenFileDescriptor(project, containingFile.getVirtualFile(), anchorOffset);
    final Editor editor = FileEditorManager.getInstance(project).openTextEditor(openDescriptor, true);
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    final Template t = templateManager.createTemplate("", "");
    if (!prefixToInsert.isEmpty())
        t.addTextSegment(prefixToInsert);
    t.addTextSegment("<!" + myElementDeclarationName + " " + myReference + " ");
    t.addEndVariable();
    t.addTextSegment(">\n");
    if (!suffixToInsert.isEmpty())
        t.addTextSegment(suffixToInsert);
    templateManager.startTemplate(editor, t);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Template(com.intellij.codeInsight.template.Template) TemplateManager(com.intellij.codeInsight.template.TemplateManager) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 98 with Editor

use of com.intellij.openapi.editor.Editor in project ideavim by JetBrains.

the class SearchGroup method highlightSearch.

private void highlightSearch(final boolean noSmartCase) {
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
        Editor current = FileEditorManager.getInstance(project).getSelectedTextEditor();
        Editor[] editors = current == null ? null : EditorFactory.getInstance().getEditors(current.getDocument(), project);
        if (editors == null) {
            continue;
        }
        for (final Editor editor : editors) {
            String els = EditorData.getLastSearch(editor);
            if (!showSearchHighlight) {
                removeSearchHighlight(editor);
                continue;
            } else if (lastSearch != null && lastSearch.equals(els)) {
                continue;
            } else if (lastSearch == null) {
                continue;
            }
            removeSearchHighlight(editor);
            highlightSearchLines(editor, lastSearch, 0, -1, shouldIgnoreCase(lastSearch, noSmartCase));
            EditorData.setLastSearch(editor, lastSearch);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) Editor(com.intellij.openapi.editor.Editor)

Example 99 with Editor

use of com.intellij.openapi.editor.Editor in project ideavim by JetBrains.

the class KeyGroup method putKeyMapping.

public void putKeyMapping(@NotNull Set<MappingMode> modes, @NotNull List<KeyStroke> fromKeys, @Nullable List<KeyStroke> toKeys, @Nullable VimExtensionHandler extensionHandler, boolean recursive) {
    for (MappingMode mode : modes) {
        final KeyMapping mapping = getKeyMapping(mode);
        mapping.put(EnumSet.of(mode), fromKeys, toKeys, extensionHandler, recursive);
    }
    final int oldSize = requiredShortcutKeys.size();
    for (KeyStroke key : fromKeys) {
        if (key.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
            requiredShortcutKeys.add(key);
        }
    }
    if (requiredShortcutKeys.size() != oldSize) {
        for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
            unregisterShortcutKeys(editor);
            registerRequiredShortcutKeys(editor);
        }
    }
}
Also used : MappingMode(com.maddyhome.idea.vim.command.MappingMode) Editor(com.intellij.openapi.editor.Editor)

Example 100 with Editor

use of com.intellij.openapi.editor.Editor in project ideavim by JetBrains.

the class VimTestCase method typeText.

@NotNull
protected Editor typeText(@NotNull List<KeyStroke> keys) {
    final Editor editor = myFixture.getEditor();
    final KeyHandler keyHandler = KeyHandler.getInstance();
    final EditorDataContext dataContext = new EditorDataContext(editor);
    final Project project = myFixture.getProject();
    TestInputModel.getInstance(editor).setKeyStrokes(keys);
    RunnableHelper.runWriteCommand(project, new Runnable() {

        @Override
        public void run() {
            final TestInputModel inputModel = TestInputModel.getInstance(editor);
            for (KeyStroke key = inputModel.nextKeyStroke(); key != null; key = inputModel.nextKeyStroke()) {
                final ExEntryPanel exEntryPanel = ExEntryPanel.getInstance();
                if (exEntryPanel.isActive()) {
                    exEntryPanel.handleKey(key);
                } else {
                    keyHandler.handleKey(editor, key, dataContext);
                }
            }
        }
    }, null, null);
    return editor;
}
Also used : Project(com.intellij.openapi.project.Project) ExEntryPanel(com.maddyhome.idea.vim.ui.ExEntryPanel) Editor(com.intellij.openapi.editor.Editor) KeyHandler(com.maddyhome.idea.vim.KeyHandler) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Editor (com.intellij.openapi.editor.Editor)748 Project (com.intellij.openapi.project.Project)281 PsiFile (com.intellij.psi.PsiFile)171 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 NotNull (org.jetbrains.annotations.NotNull)110 Document (com.intellij.openapi.editor.Document)108 PsiElement (com.intellij.psi.PsiElement)107 Nullable (org.jetbrains.annotations.Nullable)103 TextRange (com.intellij.openapi.util.TextRange)77 FileEditor (com.intellij.openapi.fileEditor.FileEditor)67 TextEditor (com.intellij.openapi.fileEditor.TextEditor)48 ArrayList (java.util.ArrayList)39 IncorrectOperationException (com.intellij.util.IncorrectOperationException)36 List (java.util.List)36 EditorEx (com.intellij.openapi.editor.ex.EditorEx)35 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)29 DataContext (com.intellij.openapi.actionSystem.DataContext)27 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)25 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)22