mirror of https://github.com/buggins/dlangui.git
Word wrap mouse offset
This commit is contained in:
parent
d2caa2a1a7
commit
278ecc75eb
|
@ -1435,9 +1435,51 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TextPosition wordWrapMouseOffset(int x, int y)
|
||||||
|
{
|
||||||
|
if(_span.length == 0)
|
||||||
|
return clientToTextPos(Point(x,y));
|
||||||
|
int selectedVisibleLine = y / _lineHeight;
|
||||||
|
|
||||||
|
LineSpan _curSpan;
|
||||||
|
|
||||||
|
int wrapLine = 0;
|
||||||
|
int curLine = 0;
|
||||||
|
bool foundWrap = false;
|
||||||
|
int accumulativeWidths = 0;
|
||||||
|
int curWrapOfSpan = 0;
|
||||||
|
|
||||||
|
lineSpanIterate(delegate(LineSpan curSpan){
|
||||||
|
while (!foundWrap)
|
||||||
|
{
|
||||||
|
if (wrapLine == selectedVisibleLine)
|
||||||
|
{
|
||||||
|
foundWrap = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
accumulativeWidths += curSpan.wrapPoints[curWrapOfSpan].wrapWidth;
|
||||||
|
wrapLine++;
|
||||||
|
curWrapOfSpan++;
|
||||||
|
if (curWrapOfSpan >= curSpan.len)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundWrap)
|
||||||
|
{
|
||||||
|
accumulativeWidths = 0;
|
||||||
|
curLine++;
|
||||||
|
}
|
||||||
|
curWrapOfSpan = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
int fakeLineHeight = curLine * _lineHeight;
|
||||||
|
return clientToTextPos(Point(x + accumulativeWidths,fakeLineHeight));
|
||||||
|
}
|
||||||
|
|
||||||
protected void selectWordByMouse(int x, int y) {
|
protected void selectWordByMouse(int x, int y) {
|
||||||
TextPosition oldCaretPos = _caretPos;
|
TextPosition oldCaretPos = _caretPos;
|
||||||
TextPosition newPos = clientToTextPos(Point(x,y));
|
TextPosition newPos = _wordWrap ? wordWrapMouseOffset(x,y) : clientToTextPos(Point(x,y));
|
||||||
TextRange r = content.wordBounds(newPos);
|
TextRange r = content.wordBounds(newPos);
|
||||||
if (r.start < r.end) {
|
if (r.start < r.end) {
|
||||||
_selectionRange = r;
|
_selectionRange = r;
|
||||||
|
@ -1453,7 +1495,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
||||||
|
|
||||||
protected void selectLineByMouse(int x, int y, bool onSameLineOnly = true) {
|
protected void selectLineByMouse(int x, int y, bool onSameLineOnly = true) {
|
||||||
TextPosition oldCaretPos = _caretPos;
|
TextPosition oldCaretPos = _caretPos;
|
||||||
TextPosition newPos = clientToTextPos(Point(x,y));
|
TextPosition newPos = _wordWrap ? wordWrapMouseOffset(x,y) : clientToTextPos(Point(x,y));
|
||||||
if (onSameLineOnly && newPos.line != oldCaretPos.line)
|
if (onSameLineOnly && newPos.line != oldCaretPos.line)
|
||||||
return; // different lines
|
return; // different lines
|
||||||
TextRange r = content.lineRange(newPos.line);
|
TextRange r = content.lineRange(newPos.line);
|
||||||
|
@ -1471,7 +1513,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
||||||
|
|
||||||
protected void updateCaretPositionByMouse(int x, int y, bool selecting) {
|
protected void updateCaretPositionByMouse(int x, int y, bool selecting) {
|
||||||
TextPosition oldCaretPos = _caretPos;
|
TextPosition oldCaretPos = _caretPos;
|
||||||
TextPosition newPos = clientToTextPos(Point(x,y));
|
TextPosition newPos = _wordWrap ? wordWrapMouseOffset(x,y) : clientToTextPos(Point(x,y));
|
||||||
if (newPos != _caretPos) {
|
if (newPos != _caretPos) {
|
||||||
_caretPos = newPos;
|
_caretPos = newPos;
|
||||||
updateSelectionAfterCursorMovement(oldCaretPos, selecting);
|
updateSelectionAfterCursorMovement(oldCaretPos, selecting);
|
||||||
|
|
Loading…
Reference in New Issue