From 83a2f2ef5c26b49ab87608dda6010e7d89c189cc Mon Sep 17 00:00:00 2001 From: James Johnson Date: Thu, 11 Jan 2018 11:56:00 -0500 Subject: [PATCH] Changed accumulation to work for both points and widths --- src/dlangui/core/editable.d | 16 +++++++++++----- src/dlangui/widgets/editors.d | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index b6f8e4de..16de7294 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -455,18 +455,24 @@ struct LineSpan { /// the wrapped text 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++) { if (i < this.wrapPoints.length - 1) { - int curWidth = this.wrapPoints[i].wrapWidth; - widthTotal += curWidth; + int curVal; + curVal = wrapPointInfo ? this.wrapPoints[i].wrapWidth : this.wrapPoints[i].wrapPos; + total += curVal; } } - return widthTotal; + return total; } } diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 6384671e..d805b2e6 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1289,7 +1289,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction if (wrapLine > 0) { LineSpan curSpan = getSpan(_caretPos.line); - xOffset = curSpan.widthAccumulation(wrapLine); + xOffset = curSpan.accumulation(wrapLine, LineSpan.WrapPointInfo.Width); } auto yOffset = -1 * _lineHeight * (wrapsUpTo(_caretPos.line) + wrapLine); caretRc.offset(_clientRect.left - xOffset, _clientRect.top - yOffset);