IDEA-53596 Soft wrap for editors

1. Soft wrap appliance point selection algorithm is corrected;
2. Visual position -> (x; y) mapping is corrected in a way to consider 'before soft wrap' sign;
This commit is contained in:
Denis Zhdanov
2010-08-10 12:40:07 +04:00
parent 767f9fc2e8
commit 6d4313bcf4
2 changed files with 12 additions and 2 deletions
@@ -1124,6 +1124,15 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
state.advance();
fontType = state.getMergedAttributes().getFontType();
}
// We need to consider 'before soft wrap drawing'.
TextChange softWrap = getSoftWrapModel().getSoftWrap(offset);
if (softWrap != null) {
column++;
x += getSoftWrapModel().getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
if (column >= length) {
break;
}
}
FoldRegion region = state.getCurrentFold();
@@ -220,12 +220,13 @@ public class DefaultSoftWrapApplianceManager implements SoftWrapApplianceManager
TIntArrayList result = new TIntArrayList();
// Find offsets where soft wraps should be applied for the logical line in case of no indent usage.
int x = myPainter.getMinDrawingWidth(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
int x = 0;
int beforeSoftWrapDrawingWidth = myPainter.getMinDrawingWidth(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
int prevSoftWrapOffset = start;
CharBuffer buffer = CharBuffer.wrap(text);
for (int i = start; i < end; i++) {
int symbolWidth = myTextRepresentationHelper.textWidth(buffer, i, i + 1, fontType, x);
if (x + symbolWidth >= myVisibleAreaWidth) {
if (x + symbolWidth + beforeSoftWrapDrawingWidth >= myVisibleAreaWidth) {
int offset = calculateSoftWrapOffset(text, i, prevSoftWrapOffset, end);
if (offset >= end || offset <= prevSoftWrapOffset) {
// There is no way to insert soft wrap.