Search in sources :

Example 1 with SoftWrapModelImpl

use of com.intellij.openapi.editor.impl.SoftWrapModelImpl 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)

Example 2 with SoftWrapModelImpl

use of com.intellij.openapi.editor.impl.SoftWrapModelImpl in project intellij-community by JetBrains.

the class IncrementalCacheUpdateEvent method getVisualLineInfo.

private static VisualLineInfo getVisualLineInfo(@NotNull EditorImpl editor, int offset, boolean beforeSoftWrap) {
    Document document = editor.getDocument();
    int textLength = document.getTextLength();
    if (offset <= 0 || textLength == 0)
        return new VisualLineInfo(0, false);
    offset = Math.min(offset, textLength);
    int startOffset = EditorUtil.getNotFoldedLineStartOffset(editor, offset);
    SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
    int wrapIndex = softWrapModel.getSoftWrapIndex(offset);
    int prevSoftWrapIndex = wrapIndex < 0 ? (-wrapIndex - 2) : wrapIndex - (beforeSoftWrap ? 1 : 0);
    SoftWrap prevSoftWrap = prevSoftWrapIndex < 0 ? null : softWrapModel.getRegisteredSoftWraps().get(prevSoftWrapIndex);
    int visualLineStartOffset = prevSoftWrap == null ? startOffset : Math.max(startOffset, prevSoftWrap.getStart());
    return new VisualLineInfo(visualLineStartOffset, prevSoftWrap != null && prevSoftWrap.getStart() == visualLineStartOffset);
}
Also used : SoftWrapModelImpl(com.intellij.openapi.editor.impl.SoftWrapModelImpl) SoftWrap(com.intellij.openapi.editor.SoftWrap) Document(com.intellij.openapi.editor.Document)

Example 3 with SoftWrapModelImpl

use of com.intellij.openapi.editor.impl.SoftWrapModelImpl in project intellij-community by JetBrains.

the class EditorCoordinateMapper method visualLineStartOffset.

private int visualLineStartOffset(int offset, boolean leanForward) {
    EditorImpl editor = myView.getEditor();
    offset = DocumentUtil.alignToCodePointBoundary(myDocument, offset);
    int result = EditorUtil.getNotFoldedLineStartOffset(editor, offset);
    SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
    List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
    int currentOrPrevWrapIndex = softWrapModel.getSoftWrapIndex(offset);
    SoftWrap currentOrPrevWrap;
    if (currentOrPrevWrapIndex < 0) {
        currentOrPrevWrapIndex = -currentOrPrevWrapIndex - 2;
        currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex);
    } else {
        currentOrPrevWrap = leanForward ? softWraps.get(currentOrPrevWrapIndex) : null;
    }
    if (currentOrPrevWrap != null && currentOrPrevWrap.getStart() > result) {
        result = currentOrPrevWrap.getStart();
    }
    return result;
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) SoftWrapModelImpl(com.intellij.openapi.editor.impl.SoftWrapModelImpl)

Example 4 with SoftWrapModelImpl

use of com.intellij.openapi.editor.impl.SoftWrapModelImpl in project intellij-community by JetBrains.

the class VisualLineFragmentsIterator method init.

private void init(EditorView view, int startOffset, int startLogicalLine, int currentOrPrevWrapIndex, int nextFoldingIndex, @Nullable Runnable quickEvaluationListener) {
    myQuickEvaluationListener = quickEvaluationListener;
    myView = view;
    EditorImpl editor = view.getEditor();
    myDocument = editor.getDocument();
    FoldingModelEx foldingModel = editor.getFoldingModel();
    FoldRegion[] regions = foldingModel.fetchTopLevel();
    myRegions = regions == null ? FoldRegion.EMPTY_ARRAY : regions;
    SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
    List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
    SoftWrap currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex);
    SoftWrap followingWrap = (currentOrPrevWrapIndex + 1) < 0 || (currentOrPrevWrapIndex + 1) >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex + 1);
    myVisualLineStartOffset = mySegmentStartOffset = startOffset;
    myCurrentFoldRegionIndex = nextFoldingIndex;
    myCurrentEndLogicalLine = startLogicalLine;
    myCurrentX = myView.getInsets().left;
    if (mySegmentStartOffset == 0) {
        myCurrentX += myView.getPrefixTextWidthInPixels();
    } else if (currentOrPrevWrap != null && mySegmentStartOffset == currentOrPrevWrap.getStart()) {
        myCurrentX += currentOrPrevWrap.getIndentInPixels();
        myCurrentVisualColumn = currentOrPrevWrap.getIndentInColumns();
    }
    myNextWrapOffset = followingWrap == null ? Integer.MAX_VALUE : followingWrap.getStart();
    setInlaysAndFragmentIterator();
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) FoldRegion(com.intellij.openapi.editor.FoldRegion) SoftWrapModelImpl(com.intellij.openapi.editor.impl.SoftWrapModelImpl) SoftWrap(com.intellij.openapi.editor.SoftWrap) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx)

Aggregations

SoftWrapModelImpl (com.intellij.openapi.editor.impl.SoftWrapModelImpl)4 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)2 Document (com.intellij.openapi.editor.Document)1 FoldRegion (com.intellij.openapi.editor.FoldRegion)1 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)1 DefaultEditorTextRepresentationHelper (com.intellij.openapi.editor.impl.DefaultEditorTextRepresentationHelper)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