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();
}
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);
}
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;
}
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();
}
Aggregations