use of com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType in project intellij-community by JetBrains.
the class EditorTestUtil method configureSoftWraps.
/**
* Configures given editor to wrap at given width, assuming characters are of given width
*
* @return whether any actual wraps of editor contents were created as a result of turning on soft wraps
*/
@TestOnly
public static boolean configureSoftWraps(Editor editor, final int visibleWidth, final int charWidthInPixels) {
editor.getSettings().setUseSoftWraps(true);
SoftWrapModelImpl model = (SoftWrapModelImpl) editor.getSoftWrapModel();
model.setSoftWrapPainter(new SoftWrapPainter() {
@Override
public int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) {
return charWidthInPixels;
}
@Override
public int getDrawingHorizontalOffset(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) {
return charWidthInPixels;
}
@Override
public int getMinDrawingWidth(@NotNull SoftWrapDrawingType drawingType) {
return charWidthInPixels;
}
@Override
public boolean canUse() {
return true;
}
@Override
public void reinit() {
}
});
model.reinitSettings();
SoftWrapApplianceManager applianceManager = model.getApplianceManager();
applianceManager.setWidthProvider(new SoftWrapApplianceManager.VisibleAreaWidthProvider() {
@Override
public int getVisibleAreaWidth() {
return visibleWidth;
}
});
model.setEditorTextRepresentationHelper(new DefaultEditorTextRepresentationHelper(editor) {
@Override
public int charWidth(int c, int fontType) {
return charWidthInPixels;
}
});
setEditorVisibleSizeInPixels(editor, visibleWidth, 1000);
applianceManager.registerSoftWrapIfNecessary();
return !model.getRegisteredSoftWraps().isEmpty();
}
Aggregations