/** * 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(char c, int fontType) { return charWidthInPixels; } }); applianceManager.registerSoftWrapIfNecessary(); return !model.getRegisteredSoftWraps().isEmpty(); }