Search in sources :

Example 1 with SoftWrapDrawingType

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();
}
Also used : SoftWrapPainter(com.intellij.openapi.editor.impl.softwrap.SoftWrapPainter) DefaultEditorTextRepresentationHelper(com.intellij.openapi.editor.impl.DefaultEditorTextRepresentationHelper) SoftWrapDrawingType(com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType) SoftWrapModelImpl(com.intellij.openapi.editor.impl.SoftWrapModelImpl) SoftWrapApplianceManager(com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager) TestOnly(org.jetbrains.annotations.TestOnly)

Aggregations

DefaultEditorTextRepresentationHelper (com.intellij.openapi.editor.impl.DefaultEditorTextRepresentationHelper)1 SoftWrapModelImpl (com.intellij.openapi.editor.impl.SoftWrapModelImpl)1 SoftWrapDrawingType (com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType)1 SoftWrapPainter (com.intellij.openapi.editor.impl.softwrap.SoftWrapPainter)1 SoftWrapApplianceManager (com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager)1 TestOnly (org.jetbrains.annotations.TestOnly)1