Search in sources :

Example 91 with EditorEx

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

the class PrevNextDifferenceIterableBase method canGoNext.

@Override
public boolean canGoNext() {
    List<? extends T> changes = getChanges();
    if (changes.isEmpty())
        return false;
    EditorEx editor = getEditor();
    int line = editor.getCaretModel().getLogicalPosition().line;
    if (line == editor.getDocument().getLineCount() - 1)
        return false;
    T lastChange = changes.get(changes.size() - 1);
    if (getStartLine(lastChange) <= line)
        return false;
    return true;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 92 with EditorEx

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

the class SyncScrollSupport method getTargetOffsets.

@NotNull
private static int[] getTargetOffsets(@NotNull Editor[] editors, int[] startLines, int[] endLines, int preferredTopShift) {
    int count = editors.length;
    assert startLines.length == count;
    assert endLines.length == count;
    int[] topOffsets = new int[count];
    int[] bottomOffsets = new int[count];
    int[] rangeHeights = new int[count];
    int[] gapLines = new int[count];
    int[] editorHeights = new int[count];
    int[] maximumOffsets = new int[count];
    int[] topShifts = new int[count];
    for (int i = 0; i < count; i++) {
        topOffsets[i] = editors[i].logicalPositionToXY(new LogicalPosition(startLines[i], 0)).y;
        bottomOffsets[i] = editors[i].logicalPositionToXY(new LogicalPosition(endLines[i] + 1, 0)).y;
        rangeHeights[i] = bottomOffsets[i] - topOffsets[i];
        gapLines[i] = 2 * editors[i].getLineHeight();
        editorHeights[i] = editors[i].getScrollingModel().getVisibleArea().height;
        maximumOffsets[i] = ((EditorEx) editors[i]).getScrollPane().getVerticalScrollBar().getMaximum() - editorHeights[i];
        // 'shift' here - distance between editor's top and first line of range
        // make whole range visible. If possible, locate it at 'center' (1/3 of height) (or at 'preferredTopShift' if it was specified)
        // If can't show whole range - show as much as we can
        boolean canShow = 2 * gapLines[i] + rangeHeights[i] <= editorHeights[i];
        int shift = preferredTopShift != -1 ? preferredTopShift : editorHeights[i] / 3;
        topShifts[i] = canShow ? Math.min(editorHeights[i] - gapLines[i] - rangeHeights[i], shift) : gapLines[i];
    }
    int topShift = ArrayUtil.min(topShifts);
    // check if we're at the top of file
    topShift = Math.min(topShift, ArrayUtil.min(topOffsets));
    int[] offsets = new int[count];
    boolean haveEnoughSpace = true;
    for (int i = 0; i < count; i++) {
        offsets[i] = topOffsets[i] - topShift;
        haveEnoughSpace &= maximumOffsets[i] > offsets[i];
    }
    if (haveEnoughSpace)
        return offsets;
    // One of the ranges is at end of file - we can't scroll where we want to.
    topShift = 0;
    for (int i = 0; i < count; i++) {
        topShift = Math.max(topOffsets[i] - maximumOffsets[i], topShift);
    }
    for (int i = 0; i < count; i++) {
        // Try to show as much of range as we can (even if it breaks alignment)
        offsets[i] = topOffsets[i] - topShift + Math.max(topShift + rangeHeights[i] + gapLines[i] - editorHeights[i], 0);
        // always show top of the range
        offsets[i] = Math.min(offsets[i], topOffsets[i] - gapLines[i]);
    }
    return offsets;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with EditorEx

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

the class DiffUtil method createEditor.

@NotNull
public static EditorEx createEditor(@NotNull Document document, @Nullable Project project, boolean isViewer, boolean enableFolding) {
    EditorFactory factory = EditorFactory.getInstance();
    EditorEx editor = (EditorEx) (isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));
    editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
    editor.getSettings().setShowIntentionBulb(false);
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
    editor.getGutterComponentEx().setShowDefaultGutterPopup(false);
    if (enableFolding) {
        setFoldingModelSupport(editor);
    } else {
        editor.getSettings().setFoldingOutlineShown(false);
        editor.getFoldingModel().setFoldingEnabled(false);
    }
    UIUtil.removeScrollBorder(editor.getComponent());
    return editor;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorMarkupModel(com.intellij.openapi.editor.ex.EditorMarkupModel)

Example 94 with EditorEx

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

the class LanguageConsoleImpl method installEditorFactoryListener.

private void installEditorFactoryListener() {
    FileEditorManagerListener fileEditorListener = new FileEditorManagerListener() {

        @Override
        public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (myConsoleEditor == null || !Comparing.equal(file, getVirtualFile())) {
                return;
            }
            Editor selectedTextEditor = source.getSelectedTextEditor();
            for (FileEditor fileEditor : source.getAllEditors(file)) {
                if (!(fileEditor instanceof TextEditor)) {
                    continue;
                }
                final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor();
                editor.addFocusListener(myFocusListener);
                if (selectedTextEditor == editor) {
                    // already focused
                    myCurrentEditor = editor;
                }
                EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent());
            }
        }

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (!Comparing.equal(file, getVirtualFile())) {
                return;
            }
            if (!Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) {
                if (myCurrentEditor != null && myCurrentEditor.isDisposed()) {
                    myCurrentEditor = null;
                }
            }
        }
    };
    myBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener);
    FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
    if (editorManager.isFileOpen(getVirtualFile())) {
        fileEditorListener.fileOpened(editorManager, getVirtualFile());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) EditorEx(com.intellij.openapi.editor.ex.EditorEx) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) NotNull(org.jetbrains.annotations.NotNull)

Example 95 with EditorEx

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

the class LightAdvHighlightingTest method testAnnotatorWorksWithFileLevel.

public void testAnnotatorWorksWithFileLevel() {
    Annotator annotator = new MyTopFileAnnotator();
    Language java = StdFileTypes.JAVA.getLanguage();
    LanguageAnnotators.INSTANCE.addExplicitExtension(java, annotator);
    try {
        List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
        assertTrue(list.toString(), list.contains(annotator));
        configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
        // whole file fit onscreen
        ((EditorEx) getEditor()).getScrollPane().getViewport().setSize(new Dimension(1000, 1000));
        doHighlighting();
        List<HighlightInfo> fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        HighlightInfo info = assertOneElement(fileLevel);
        assertEquals("top level", info.getDescription());
        type("\n\n");
        doHighlighting();
        fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        info = assertOneElement(fileLevel);
        assertEquals("top level", info.getDescription());
        //disable top level annotation
        type("//xxx");
        List<HighlightInfo> warnings = doHighlighting(HighlightSeverity.WARNING);
        assertEmpty(warnings);
        fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        assertEmpty(fileLevel);
    } finally {
        LanguageAnnotators.INSTANCE.removeExplicitExtension(java, annotator);
    }
    List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
    assertFalse(list.toString(), list.contains(annotator));
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Language(com.intellij.lang.Language) Annotator(com.intellij.lang.annotation.Annotator) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)

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