Skip to content

Commit 03141c2

Browse files
committed
Use engine's getWordBoundary method when user selects a word. (flutter#3851)
1 parent 616d9e2 commit 03141c2

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

packages/flutter/lib/src/painting/text_painter.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,9 @@ class TextPainter {
229229
return _paragraph.getPositionForOffset(offset);
230230
}
231231

232+
TextRange getWordBoundary(TextPosition position) {
233+
assert(!_needsLayout);
234+
List<int> indices = _paragraph.getWordBoundary(position.offset);
235+
return new TextRange(start: indices[0], end: indices[1]);
236+
}
232237
}

packages/flutter/lib/src/rendering/editable_line.dart

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,8 @@ class RenderEditableLine extends RenderBox {
232232
}
233233

234234
TextSelection _selectWordAtOffset(TextPosition position) {
235-
// TODO(mpcomplete): Placeholder. Need to ask the engine for this info to do
236-
// it correctly.
237-
String str = text.toPlainText();
238-
int start = position.offset - 1;
239-
while (start >= 0 && str[start] != ' ')
240-
--start;
241-
++start;
242-
243-
int end = position.offset;
244-
while (end < str.length && str[end] != ' ')
245-
++end;
246-
247-
return new TextSelection(baseOffset: start, extentOffset: end);
235+
TextRange word = _textPainter.getWordBoundary(position);
236+
return new TextSelection(baseOffset: word.start, extentOffset: word.end);
248237
}
249238

250239
Rect _caretPrototype;

0 commit comments

Comments
 (0)