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);
}
}
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());
}
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>?");
}
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");
}
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]);
}
Aggregations