Skip to content

Commit e0b9a2b

Browse files
authored
Change wordBoundary to take dynamic temporarily (flutter#13765)
Converting the argument to Paragraph.wordBoundary to dynamic temporarily until the framework code is converted to send a TextPosition instead of an int. I'll submit this, then update the framework side to send a TextPosition, and expect a TextRange or a List<int>, and then submit that, then I'll change this code to send a TextRange and take a TextPostion only, removing the dynamic here. Once that's done, I'll remove the code in the framework that expects a TextRange or a List<int>, and have it just expect a TextRange. This is so that we can change the API without breaking the builds. Landing on red to kick the engine builds.
1 parent a8f678e commit e0b9a2b

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

lib/ui/text.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,17 @@ class Paragraph extends NativeFieldWrapperClass2 {
18711871
/// on both sides. In such cases, this method will return [offset, offset+1].
18721872
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
18731873
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1874-
List<int> getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
1874+
List<int> getWordBoundary(dynamic position) {
1875+
// TODO(gspencergoog): have this take only a TextPosition once the framework
1876+
// code is calling it with that.
1877+
if (position is TextPosition) {
1878+
return _getWordBoundary(position.offset);
1879+
} else {
1880+
final int offset = position;
1881+
return _getWordBoundary(offset);
1882+
}
1883+
}
1884+
List<int> _getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
18751885

18761886
// Redirecting the paint function in this way solves some dependency problems
18771887
// in the C++ code. If we straighten out the C++ dependencies, we can remove

lib/web_ui/lib/src/engine/text/paragraph.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,26 @@ class EngineParagraph implements ui.Paragraph {
281281
}
282282

283283
@override
284-
List<int> getWordBoundary(int offset) {
284+
List<int> getWordBoundary(dynamic position) {
285+
// TODO(gspencergoog): have this take only a TextPosition once the framework
286+
// code is calling it with that.
287+
if (position is ui.TextPosition) {
288+
ui.TextPosition textPosition = position;
289+
if (_plainText == null) {
290+
return <int>[textPosition.offset, textPosition.offset];
291+
}
292+
293+
final int start = WordBreaker.prevBreakIndex(_plainText, textPosition.offset);
294+
final int end = WordBreaker.nextBreakIndex(_plainText, textPosition.offset);
295+
return <int>[start, end];
296+
}
297+
285298
if (_plainText == null) {
286-
return <int>[offset, offset];
299+
return <int>[position, position];
287300
}
288301

289-
final int start = WordBreaker.prevBreakIndex(_plainText, offset);
290-
final int end = WordBreaker.nextBreakIndex(_plainText, offset);
302+
final int start = WordBreaker.prevBreakIndex(_plainText, position);
303+
final int end = WordBreaker.nextBreakIndex(_plainText, position);
291304
return <int>[start, end];
292305
}
293306

lib/web_ui/lib/src/ui/text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ abstract class Paragraph {
12421242
/// on both sides. In such cases, this method will return [offset, offset+1].
12431243
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
12441244
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1245-
List<int> getWordBoundary(int offset);
1245+
List<int> getWordBoundary(dynamic position);
12461246

12471247
/// Returns a list of text boxes that enclose all placeholders in the paragraph.
12481248
///

0 commit comments

Comments
 (0)