Search in sources :

Example 21 with EditorImpl

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

the class TrafficLightRenderer method setOrRefreshErrorStripeRenderer.

static void setOrRefreshErrorStripeRenderer(@NotNull EditorMarkupModel editorMarkupModel, @NotNull Project project, @NotNull Document document, PsiFile file) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (!editorMarkupModel.isErrorStripeVisible() || !DaemonCodeAnalyzer.getInstance(project).isHighlightingAvailable(file)) {
        return;
    }
    ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer();
    if (renderer instanceof TrafficLightRenderer) {
        TrafficLightRenderer tlr = (TrafficLightRenderer) renderer;
        tlr.refresh();
        ((EditorMarkupModelImpl) editorMarkupModel).repaintVerticalScrollBar();
        if (tlr.myFile == null || tlr.myFile.isValid())
            return;
        Disposer.dispose(tlr);
    }
    EditorImpl editor = (EditorImpl) editorMarkupModel.getEditor();
    if (!editor.isDisposed()) {
        renderer = new TrafficLightRenderer(project, document, file);
        Disposer.register(editor.getDisposable(), (Disposable) renderer);
        editorMarkupModel.setErrorStripeRenderer(renderer);
    }
}
Also used : ErrorStripeRenderer(com.intellij.openapi.editor.markup.ErrorStripeRenderer) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) EditorMarkupModelImpl(com.intellij.openapi.editor.impl.EditorMarkupModelImpl)

Example 22 with EditorImpl

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

the class FindInEditorMultiCaretTest method testActionsInEditorWorkIndependently.

public void testActionsInEditorWorkIndependently() throws IOException {
    init("abc\n" + "abc\n" + "abc");
    initFind();
    setTextToFind("b");
    checkResultByText("a<selection>b<caret></selection>c\n" + "abc\n" + "abc");
    new EditorMouseFixture((EditorImpl) myFixture.getEditor()).clickAt(0, 1);
    addOccurrenceFromEditor();
    addOccurrenceFromEditor();
    checkResultByText("<selection>a<caret>bc</selection>\n" + "<selection>a<caret>bc</selection>\n" + "abc");
    nextOccurrenceFromEditor();
    checkResultByText("<selection>a<caret>bc</selection>\n" + "abc\n" + "<selection>a<caret>bc</selection>");
    prevOccurrenceFromEditor();
    checkResultByText("<selection>a<caret>bc</selection>\n" + "<selection>a<caret>bc</selection>\n" + "abc");
    removeOccurrenceFromEditor();
    checkResultByText("<selection>a<caret>bc</selection>\n" + "abc\n" + "abc");
    allOccurrencesFromEditor();
    checkResultByText("<selection>a<caret>bc</selection>\n" + "<selection>a<caret>bc</selection>\n" + "<selection>a<caret>bc</selection>");
    assertNotNull(getEditorSearchComponent());
}
Also used : EditorMouseFixture(com.intellij.testFramework.fixtures.EditorMouseFixture) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl)

Example 23 with EditorImpl

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

the class FindInEditorMultiCaretTest method testFindNextRetainsOnlyOneCaretIfNotUsedAsMoveToNextOccurrence.

public void testFindNextRetainsOnlyOneCaretIfNotUsedAsMoveToNextOccurrence() throws Exception {
    init("<caret>To be or not to be?");
    initFind();
    setTextToFind("be");
    checkResultByText("To <selection>be<caret></selection> or not to be?");
    closeFind();
    // adding second caret
    new EditorMouseFixture((EditorImpl) myFixture.getEditor()).alt().shift().clickAt(0, 8);
    checkResultByText("To <selection>be<caret></selection> or<caret> not to be?");
    nextOccurrenceFromEditor();
    checkResultByText("To be or not to <selection>be<caret></selection>?");
}
Also used : EditorMouseFixture(com.intellij.testFramework.fixtures.EditorMouseFixture) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl)

Example 24 with EditorImpl

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

the class DaemonRespondToChangesTest method testCancelsItSelfOnTypingInAlienProject.

public void testCancelsItSelfOnTypingInAlienProject() throws Throwable {
    String body = StringUtil.repeat("\"String field = null;\"\n", 1000);
    configureByText(StdFileTypes.JAVA, "class X{ void f() {" + body + "<caret>\n} }");
    File temp = createTempDirectory();
    final Project alienProject = createProject(temp + "/alien.ipr", DebugUtil.currentStackTrace());
    boolean succ2 = ProjectManagerEx.getInstanceEx().openProject(alienProject);
    assertTrue(succ2);
    DaemonProgressIndicator.setDebug(true);
    try {
        Module alienModule = doCreateRealModuleIn("x", alienProject, getModuleType());
        final VirtualFile alienRoot = PsiTestUtil.createTestProjectStructure(alienProject, alienModule, myFilesToDelete);
        OpenFileDescriptor alienDescriptor = new WriteAction<OpenFileDescriptor>() {

            @Override
            protected void run(@NotNull Result<OpenFileDescriptor> result) throws Throwable {
                VirtualFile alienFile = alienRoot.createChildData(this, "X.java");
                setFileText(alienFile, "class Alien { }");
                OpenFileDescriptor alienDescriptor = new OpenFileDescriptor(alienProject, alienFile);
                result.setResult(alienDescriptor);
            }
        }.execute().throwException().getResultObject();
        FileEditorManager fe = FileEditorManager.getInstance(alienProject);
        final Editor alienEditor = fe.openTextEditor(alienDescriptor, false);
        ((EditorImpl) alienEditor).setCaretActive();
        PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
        PsiDocumentManager.getInstance(alienProject).commitAllDocuments();
        // start daemon in main project. should check for its cancel when typing in alien
        TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
        DaemonCodeAnalyzerImpl di = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
        final boolean[] checked = { false };
        di.runPasses(getFile(), getEditor().getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, true, () -> {
            if (checked[0])
                return;
            checked[0] = true;
            typeInAlienEditor(alienEditor, 'x');
        });
    } catch (ProcessCanceledException ignored) {
        //System.out.println("indicator = " + indicator[0]);
        return;
    } finally {
        ProjectManagerEx.getInstanceEx().closeAndDispose(alienProject);
    }
    fail("must throw PCE");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TextEditor(com.intellij.openapi.fileEditor.TextEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Module(com.intellij.openapi.module.Module) TextEditor(com.intellij.openapi.fileEditor.TextEditor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 25 with EditorImpl

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

the class DaemonRespondToChangesTest method testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong.

public void testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong() throws Throwable {
    String text = "class X{\nint xxx;\n{\nint i = <selection>null</selection><caret>;\n" + StringUtil.repeat("{ this.hashCode(); }\n\n\n", 10000) + "}}";
    configureByText(StdFileTypes.JAVA, text);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(100, 100);
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
    myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setViewPosition(new Point(0, 0));
    ((EditorImpl) myEditor).getScrollPane().getViewport().setExtentSize(new Dimension(100, 100000));
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(getEditor());
    assertTrue(visibleRange.getLength() > 0);
    final Document document = myEditor.getDocument();
    assertTrue(visibleRange.getLength() < document.getTextLength());
    List<HighlightInfo> err1 = highlightErrors();
    HighlightInfo info = assertOneElement(err1);
    final String errorDescription = "Incompatible types. Found: 'null', required: 'int'";
    assertEquals(errorDescription, info.getDescription());
    MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, false);
    final boolean[] errorRemoved = { false };
    model.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            Object tt = highlighter.getErrorStripeTooltip();
            if (!(tt instanceof HighlightInfo))
                return;
            String description = ((HighlightInfo) tt).getDescription();
            if (errorDescription.equals(description)) {
                errorRemoved[0] = true;
                List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
                GeneralHighlightingPass ghp = null;
                for (TextEditorHighlightingPass pass : passes) {
                    if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
                        assert ghp == null : ghp;
                        ghp = (GeneralHighlightingPass) pass;
                    }
                }
                assertNotNull(ghp);
                boolean finished = ghp.isFinished();
                assertFalse(finished);
            }
        }
    });
    type("1");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    assertTrue(errorRemoved[0]);
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) ProperTextRange(com.intellij.openapi.util.ProperTextRange) MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Aggregations

EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)34 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)8 Editor (com.intellij.openapi.editor.Editor)7 LightweightHint (com.intellij.ui.LightweightHint)6 Document (com.intellij.openapi.editor.Document)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 EditorMouseFixture (com.intellij.testFramework.fixtures.EditorMouseFixture)3 NotNull (org.jetbrains.annotations.NotNull)3 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)2 SoftWrapModelImpl (com.intellij.openapi.editor.impl.SoftWrapModelImpl)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Project (com.intellij.openapi.project.Project)2 HintHint (com.intellij.ui.HintHint)2 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1