From 71931c8e43f5bd0b3e1710c3b0a19aae9657e624 Mon Sep 17 00:00:00 2001 From: James Johnson Date: Thu, 11 Jan 2018 17:41:18 -0500 Subject: [PATCH] Basic implementation for highlighting text selection in word wrap --- src/dlangui/widgets/editors.d | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 57b91f53..55d6ca89 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -3336,7 +3336,23 @@ class EditBox : EditWidgetBase { Rect rc = lineRect; rc.left = startx; rc.right = endx; - if (!rc.empty) { + if (!rc.empty && _wordWrap) + { + auto limitNumber = (int num, int limit) => num > limit ? limit : num; + LineSpan curSpan = getSpan(lineIndex); + int yOffset = _lineHeight * (wrapsUpTo(lineIndex)); + rc.offset(0, yOffset); + Rect[] wrappedSelection; + wrappedSelection.length = curSpan.len; + foreach (int i, wrapLineRect; wrappedSelection) + { + wrapLineRect = rc; + wrapLineRect.offset(-1 * curSpan.accumulation(i, LineSpan.WrapPointInfo.Width), i * _lineHeight); + wrapLineRect.right = limitNumber(wrapLineRect.right,(rc.left + curSpan.wrapPoints[i].wrapWidth)); + buf.fillRect(wrapLineRect, focused ? _selectionColorFocused : _selectionColorNormal); + } + } + else if (!rc.empty) { // draw selection rect for line buf.fillRect(rc, focused ? _selectionColorFocused : _selectionColorNormal); }