use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class FormatterTestCase method checkDocument.
protected void checkDocument(final PsiFile file, final String text, String textAfter) {
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
final EditorImpl editor;
if (doCheckDocumentUpdate()) {
editor = (EditorImpl) FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file.getVirtualFile(), 0), false);
editor.putUserData(EditorImpl.DO_DOCUMENT_UPDATE_TEST, Boolean.TRUE);
if (myFile != null) {
FileEditorManager.getInstance(getProject()).closeFile(myFile.getVirtualFile());
}
myEditor = editor;
myFile = file;
} else {
editor = null;
}
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
document.replaceString(0, document.getTextLength(), text);
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
assertEquals(file.getText(), document.getText());
try {
if (doReformatRangeTest) {
CodeStyleManager.getInstance(getProject()).reformatRange(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
} else if (myTextRange != null) {
CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset());
} else {
CodeStyleManager.getInstance(getProject()).reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
}
} catch (IncorrectOperationException e) {
fail();
}
});
assertEquals(textAfter, document.getText());
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
assertEquals(textAfter, file.getText());
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class AbstractValueHint method showHint.
protected boolean showHint(final JComponent component) {
myInsideShow = true;
if (myCurrentHint != null) {
myCurrentHint.hide();
}
myCurrentHint = new LightweightHint(component) {
@Override
protected boolean canAutoHideOn(TooltipEvent event) {
InputEvent inputEvent = event.getInputEvent();
if (inputEvent instanceof MouseEvent) {
Component comp = inputEvent.getComponent();
if (comp instanceof EditorComponentImpl) {
EditorImpl editor = ((EditorComponentImpl) comp).getEditor();
return !isInsideCurrentRange(editor, ((MouseEvent) inputEvent).getPoint());
}
}
return true;
}
};
myCurrentHint.addHintListener(new HintListener() {
@Override
public void hintHidden(EventObject event) {
if (myHideRunnable != null && !myInsideShow) {
myHideRunnable.run();
}
onHintHidden();
}
});
// editor may be disposed before later invokator process this action
if (myEditor.isDisposed() || myEditor.getComponent().getRootPane() == null) {
return false;
}
Point p = HintManagerImpl.getHintPosition(myCurrentHint, myEditor, myEditor.xyToLogicalPosition(myPoint), HintManager.UNDER);
HintHint hint = HintManagerImpl.createHintHint(myEditor, p, myCurrentHint, HintManager.UNDER, true);
hint.setShowImmediately(true);
HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, myEditor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hint);
myInsideShow = false;
return true;
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class CoverageLineMarkerRenderer method showHint.
private void showHint(final Editor editor, final Point point, final int lineNumber) {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);
final LineData lineData = getLineData(lineNumber);
final EditorImpl uEditor;
if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
final EditorFactory factory = EditorFactory.getInstance();
final Document doc = factory.createDocument(getReport(editor, lineNumber));
doc.setReadOnly(true);
uEditor = (EditorImpl) factory.createEditor(doc, editor.getProject());
panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
} else {
uEditor = null;
}
final LightweightHint hint = new LightweightHint(panel) {
@Override
public void hide() {
if (uEditor != null)
EditorFactory.getInstance().releaseEditor(uEditor);
super.hide();
}
};
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-plugins by JetBrains.
the class SwfHighlightingTest method testLineMarkersInSwf.
@JSTestOptions({ JSTestOption.WithFlexFacet, JSTestOption.WithLineMarkers })
public void testLineMarkersInSwf() throws Exception {
final String testName = getTestName(false);
myAfterCommitRunnable = () -> FlexTestUtils.addLibrary(myModule, "lib", getTestDataPath() + getBasePath() + "/", testName + ".swc", null, null);
// actual test data is in library.swf; this file is here just because we need any file
configureByFile("/" + testName + ".as");
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".swc");
vFile = JarFileSystem.getInstance().getJarRootForLocalFile(vFile).findChild("library.swf");
myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
myFile = myPsiManager.findFile(vFile);
((EditorImpl) myEditor).setCaretActive();
vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".as");
final String verificationText = StreamUtil.convertSeparators(VfsUtilCore.loadText(vFile));
checkHighlighting(new ExpectedHighlightingData(new DocumentImpl(verificationText), false, false, true, myFile));
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-plugins by JetBrains.
the class SwfHighlightingTest method testProtectSwf.
public void testProtectSwf() throws Exception {
configureByFiles((String) null);
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + getTestName(false) + ".swf");
myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
myFile = myPsiManager.findFile(vFile);
((EditorImpl) myEditor).setCaretActive();
assertFalse(FileDocumentManager.getInstance().requestWriting(myEditor.getDocument(), myProject));
}
Aggregations