Use engine's getWordBoundary method when user selects a word. (#3851)

This commit is contained in:
Matt Perry 2016-05-12 15:31:01 -04:00
parent 616d9e2ea8
commit 03141c2cdd
2 changed files with 7 additions and 13 deletions

View File

@ -229,4 +229,9 @@ class TextPainter {
return _paragraph.getPositionForOffset(offset);
}
TextRange getWordBoundary(TextPosition position) {
assert(!_needsLayout);
List<int> indices = _paragraph.getWordBoundary(position.offset);
return new TextRange(start: indices[0], end: indices[1]);
}
}

View File

@ -232,19 +232,8 @@ class RenderEditableLine extends RenderBox {
}
TextSelection _selectWordAtOffset(TextPosition position) {
// TODO(mpcomplete): Placeholder. Need to ask the engine for this info to do
// it correctly.
String str = text.toPlainText();
int start = position.offset - 1;
while (start >= 0 && str[start] != ' ')
--start;
++start;
int end = position.offset;
while (end < str.length && str[end] != ' ')
++end;
return new TextSelection(baseOffset: start, extentOffset: end);
TextRange word = _textPainter.getWordBoundary(position);
return new TextSelection(baseOffset: word.start, extentOffset: word.end);
}
Rect _caretPrototype;