use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class LineMarkersUtil method setLineMarkersToEditor.
static void setLineMarkersToEditor(@NotNull Project project, @NotNull Document document, @NotNull Segment bounds, @NotNull Collection<LineMarkerInfo> markers, int group) {
ApplicationManager.getApplication().assertIsDispatchThread();
MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true);
HighlightersRecycler toReuse = new HighlightersRecycler();
processLineMarkers(project, document, bounds, group, info -> {
toReuse.recycleHighlighter(info.highlighter);
return true;
});
if (LOG.isDebugEnabled()) {
List<LineMarkerInfo> oldMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
LOG.debug("LineMarkersUtil.setLineMarkersToEditor(markers: " + markers + ", group: " + group + "); oldMarkers: " + oldMarkers + "; reused: " + toReuse.forAllInGarbageBin().size());
}
for (final LineMarkerInfo info : markers) {
PsiElement element = info.getElement();
if (element == null) {
continue;
}
TextRange textRange = element.getTextRange();
if (textRange == null)
continue;
TextRange elementRange = InjectedLanguageManager.getInstance(project).injectedToHost(element, textRange);
if (!TextRange.containsRange(bounds, elementRange)) {
continue;
}
createOrReuseLineMarker(info, markupModel, toReuse);
}
for (RangeHighlighter highlighter : toReuse.forAllInGarbageBin()) {
highlighter.dispose();
}
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class LineMarkersUtil method addLineMarkerToEditorIncrementally.
static void addLineMarkerToEditorIncrementally(@NotNull Project project, @NotNull Document document, @NotNull LineMarkerInfo marker) {
ApplicationManager.getApplication().assertIsDispatchThread();
MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true);
LineMarkerInfo[] markerInTheWay = { null };
boolean allIsClear = markupModel.processRangeHighlightersOverlappingWith(marker.startOffset, marker.endOffset, highlighter -> (markerInTheWay[0] = getLineMarkerInfo(highlighter)) == null);
if (allIsClear) {
createOrReuseLineMarker(marker, markupModel, null);
}
if (LOG.isDebugEnabled()) {
LOG.debug("LineMarkersUtil.addLineMarkerToEditorIncrementally: " + marker + " " + (allIsClear ? "created" : " (was not added because " + markerInTheWay[0] + " was in the way)"));
}
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class EmmetPreviewHint method createHint.
@NotNull
public static EmmetPreviewHint createHint(@NotNull final EditorEx parentEditor, @NotNull String templateText, @NotNull FileType fileType) {
EditorFactory editorFactory = EditorFactory.getInstance();
Document document = editorFactory.createDocument(templateText);
final EditorEx previewEditor = (EditorEx) editorFactory.createEditor(document, parentEditor.getProject(), fileType, true);
MarkupModelEx model = previewEditor.getMarkupModel();
if (model instanceof EditorMarkupModel) {
((EditorMarkupModel) model).setErrorStripeVisible(true);
}
final EditorSettings settings = previewEditor.getSettings();
settings.setLineNumbersShown(false);
settings.setAdditionalLinesCount(1);
settings.setAdditionalColumnsCount(1);
settings.setRightMarginShown(false);
settings.setFoldingOutlineShown(false);
settings.setLineMarkerAreaShown(false);
settings.setIndentGuidesShown(false);
settings.setVirtualSpace(false);
settings.setWheelFontChangeEnabled(false);
settings.setAdditionalPageAtBottom(false);
settings.setCaretRowShown(false);
previewEditor.setCaretEnabled(false);
previewEditor.setBorder(IdeBorderFactory.createEmptyBorder());
JBPanel panel = new JBPanel(new BorderLayout()) {
@NotNull
@Override
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
Dimension parentEditorSize = parentEditor.getScrollPane().getSize();
int maxWidth = (int) parentEditorSize.getWidth() / 3;
int maxHeight = (int) parentEditorSize.getHeight() / 2;
final int width = settings.isUseSoftWraps() ? maxWidth : Math.min((int) size.getWidth(), maxWidth);
final int height = Math.min((int) size.getHeight(), maxHeight);
return new Dimension(width, height);
}
@NotNull
@Override
public Insets getInsets() {
return new Insets(1, 2, 0, 0);
}
};
panel.setBackground(previewEditor.getBackgroundColor());
panel.add(previewEditor.getComponent(), BorderLayout.CENTER);
return new EmmetPreviewHint(panel, previewEditor, parentEditor);
}
Aggregations