use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testApplyErrorInTheMiddle.
public void testApplyErrorInTheMiddle() throws Throwable {
String text = "class <caret>X { ";
for (int i = 0; i < 100; i++) {
text += "\n {\n" + "// String x = \"<zzzzzzzzzz/>\";\n" + " }";
}
text += "\n}";
configureByText(StdFileTypes.JAVA, text);
((EditorImpl) myEditor).getScrollPane().getViewport().setSize(1000, 1000);
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
List<HighlightInfo> warns = highlightErrors();
assertEmpty(warns);
type("//");
List<HighlightInfo> errors = highlightErrors();
assertEquals(2, errors.size());
backspace();
backspace();
errors = highlightErrors();
assertEmpty(errors);
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class CodeInsightTestCase method createEditor.
protected Editor createEditor(@NotNull VirtualFile file) {
final FileEditorManager instance = FileEditorManager.getInstance(myProject);
if (file.getFileType().isBinary())
return null;
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
Editor editor = instance.openTextEditor(new OpenFileDescriptor(myProject, file, 0), false);
((EditorImpl) editor).setCaretActive();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
DaemonCodeAnalyzer.getInstance(getProject()).restart();
return editor;
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class EditorFragmentComponent method doInit.
private void doInit(Component anchorComponent, EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
Document doc = editor.getDocument();
final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength();
boolean newRendering = editor instanceof EditorImpl;
int widthAdjustment = newRendering ? EditorUtil.getSpaceWidth(Font.PLAIN, editor) : 0;
final int textImageWidth = Math.min(editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset) + widthAdjustment, getWidthLimit(editor));
FoldingModelEx foldingModel = editor.getFoldingModel();
boolean isFoldingEnabled = foldingModel.isFoldingEnabled();
if (!showFolding) {
foldingModel.setFoldingEnabled(false);
}
Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0));
Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0));
int y1 = p1.y;
int y2 = p2.y;
final int textImageHeight = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1;
LOG.assertTrue(textImageHeight > 0, "Height: " + textImageHeight + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2);
int savedScrollOffset = newRendering ? 0 : editor.getScrollingModel().getHorizontalScrollOffset();
if (savedScrollOffset > 0) {
editor.getScrollingModel().scrollHorizontally(0);
}
final BufferedImage textImage = UIUtil.createImage(anchorComponent == null ? editor.getContentComponent() : anchorComponent, textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
Graphics textGraphics = textImage.getGraphics();
EditorUIUtil.setupAntialiasing(textGraphics);
final JComponent rowHeader;
final BufferedImage markersImage;
final int markersImageWidth;
if (showGutter) {
rowHeader = editor.getGutterComponentEx();
markersImageWidth = Math.max(1, rowHeader.getWidth());
markersImage = UIUtil.createImage(editor.getComponent(), markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
Graphics markerGraphics = markersImage.getGraphics();
EditorUIUtil.setupAntialiasing(markerGraphics);
markerGraphics.translate(0, -y1);
markerGraphics.setClip(0, y1, rowHeader.getWidth(), textImageHeight);
markerGraphics.setColor(getBackgroundColor(editor));
markerGraphics.fillRect(0, y1, rowHeader.getWidth(), textImageHeight);
rowHeader.paint(markerGraphics);
} else {
markersImageWidth = 0;
rowHeader = null;
markersImage = null;
}
textGraphics.translate(0, -y1);
textGraphics.setClip(0, y1, textImageWidth, textImageHeight);
final boolean wasVisible = editor.setCaretVisible(false);
editor.getContentComponent().paint(textGraphics);
if (wasVisible) {
editor.setCaretVisible(true);
}
if (!showFolding) {
foldingModel.setFoldingEnabled(isFoldingEnabled);
}
if (savedScrollOffset > 0) {
editor.getScrollingModel().scrollHorizontally(savedScrollOffset);
}
JComponent component = new JComponent() {
@Override
public Dimension getPreferredSize() {
return new Dimension(textImageWidth + markersImageWidth, textImageHeight);
}
@Override
protected void paintComponent(Graphics graphics) {
if (markersImage != null) {
UIUtil.drawImage(graphics, markersImage, 0, 0, null);
UIUtil.drawImage(graphics, textImage, rowHeader.getWidth(), 0, null);
} else {
UIUtil.drawImage(graphics, textImage, 0, 0, null);
}
}
};
setLayout(new BorderLayout());
add(component);
final Color borderColor = editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR);
Border outsideBorder = JBUI.Borders.customLine(borderColor, LINE_BORDER_THICKNESS);
Border insideBorder = JBUI.Borders.empty(EMPTY_BORDER_THICKNESS, EMPTY_BORDER_THICKNESS);
setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class EventLogConsole method installNotificationsFont.
private void installNotificationsFont(@NotNull final EditorEx editor) {
final DelegateColorScheme globalScheme = new DelegateColorScheme(EditorColorsManager.getInstance().getGlobalScheme()) {
@Override
public String getEditorFontName() {
return getConsoleFontName();
}
@Override
public int getEditorFontSize() {
return getConsoleFontSize();
}
@Override
public String getConsoleFontName() {
return NotificationsUtil.getFontName();
}
@Override
public int getConsoleFontSize() {
Pair<String, Integer> data = NotificationsUtil.getFontData();
return data == null ? super.getConsoleFontSize() : data.second;
}
@Override
public void setEditorFontName(String fontName) {
}
@Override
public void setConsoleFontName(String fontName) {
}
@Override
public void setEditorFontSize(int fontSize) {
}
@Override
public void setConsoleFontSize(int fontSize) {
}
};
ApplicationManager.getApplication().getMessageBus().connect(myProjectModel).subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
globalScheme.setDelegate(EditorColorsManager.getInstance().getGlobalScheme());
editor.reinitSettings();
}
});
editor.setColorsScheme(ConsoleViewUtil.updateConsoleColorScheme(editor.createBoundColorSchemeDelegate(globalScheme)));
if (editor instanceof EditorImpl) {
((EditorImpl) editor).setUseEditorAntialiasing(false);
}
}
use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.
the class SoftWrapApplianceOnDocumentModificationTest method testLeadingTabWithShiftedWidth.
public void testLeadingTabWithShiftedWidth() throws IOException {
// Inspired by IDEA-76353. The point is that we need to consider cached information about tab symbols width during logical
// position to offset mapping
String text = "\t test";
init(15, text);
((EditorImpl) myEditor).setPrefixTextAndAttributes(" ", new TextAttributes());
myEditor.getCaretModel().moveToOffset(text.length());
}
Aggregations