Changed accumulation to work for both points and widths

This commit is contained in:
James Johnson 2018-01-11 11:56:00 -05:00
parent ce39c13e31
commit 83a2f2ef5c
2 changed files with 12 additions and 6 deletions

View File

@ -455,18 +455,24 @@ struct LineSpan {
/// the wrapped text /// the wrapped text
dstring[] wrappedContent; dstring[] wrappedContent;
int widthAccumulation(int wrapLine) enum WrapPointInfo : bool {
Position,
Width,
}
int accumulation(int wrapLine, bool wrapPointInfo)
{ {
int widthTotal; int total;
for (int i; i < wrapLine; i++) for (int i; i < wrapLine; i++)
{ {
if (i < this.wrapPoints.length - 1) if (i < this.wrapPoints.length - 1)
{ {
int curWidth = this.wrapPoints[i].wrapWidth; int curVal;
widthTotal += curWidth; curVal = wrapPointInfo ? this.wrapPoints[i].wrapWidth : this.wrapPoints[i].wrapPos;
total += curVal;
} }
} }
return widthTotal; return total;
} }
} }

View File

@ -1289,7 +1289,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
if (wrapLine > 0) if (wrapLine > 0)
{ {
LineSpan curSpan = getSpan(_caretPos.line); LineSpan curSpan = getSpan(_caretPos.line);
xOffset = curSpan.widthAccumulation(wrapLine); xOffset = curSpan.accumulation(wrapLine, LineSpan.WrapPointInfo.Width);
} }
auto yOffset = -1 * _lineHeight * (wrapsUpTo(_caretPos.line) + wrapLine); auto yOffset = -1 * _lineHeight * (wrapsUpTo(_caretPos.line) + wrapLine);
caretRc.offset(_clientRect.left - xOffset, _clientRect.top - yOffset); caretRc.offset(_clientRect.left - xOffset, _clientRect.top - yOffset);