From 4b6b7f6e965e082a753b230e9fa37aa5997f9e07 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Fri, 8 Nov 2019 16:27:00 -0800 Subject: [PATCH] Change wordBoundary to take dynamic temporarily (flutter/engine#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, 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, 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. --- engine/src/flutter/lib/ui/text.dart | 12 +++++++++- .../web_ui/lib/src/engine/text/paragraph.dart | 23 +++++++++++++++---- .../flutter/lib/web_ui/lib/src/ui/text.dart | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/lib/ui/text.dart b/engine/src/flutter/lib/ui/text.dart index 94a88b0cb3..a2a8df2057 100644 --- a/engine/src/flutter/lib/ui/text.dart +++ b/engine/src/flutter/lib/ui/text.dart @@ -1871,7 +1871,17 @@ class Paragraph extends NativeFieldWrapperClass2 { /// on both sides. In such cases, this method will return [offset, offset+1]. /// Word boundaries are defined more precisely in Unicode Standard Annex #29 /// http://www.unicode.org/reports/tr29/#Word_Boundaries - List getWordBoundary(int offset) native 'Paragraph_getWordBoundary'; + List getWordBoundary(dynamic position) { + // TODO(gspencergoog): have this take only a TextPosition once the framework + // code is calling it with that. + if (position is TextPosition) { + return _getWordBoundary(position.offset); + } else { + final int offset = position; + return _getWordBoundary(offset); + } + } + List _getWordBoundary(int offset) native 'Paragraph_getWordBoundary'; // Redirecting the paint function in this way solves some dependency problems // in the C++ code. If we straighten out the C++ dependencies, we can remove diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart index 6574cbddbc..0c53962ddc 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -281,13 +281,26 @@ class EngineParagraph implements ui.Paragraph { } @override - List getWordBoundary(int offset) { - if (_plainText == null) { - return [offset, offset]; + List getWordBoundary(dynamic position) { + // TODO(gspencergoog): have this take only a TextPosition once the framework + // code is calling it with that. + if (position is ui.TextPosition) { + ui.TextPosition textPosition = position; + if (_plainText == null) { + return [textPosition.offset, textPosition.offset]; + } + + final int start = WordBreaker.prevBreakIndex(_plainText, textPosition.offset); + final int end = WordBreaker.nextBreakIndex(_plainText, textPosition.offset); + return [start, end]; } - final int start = WordBreaker.prevBreakIndex(_plainText, offset); - final int end = WordBreaker.nextBreakIndex(_plainText, offset); + if (_plainText == null) { + return [position, position]; + } + + final int start = WordBreaker.prevBreakIndex(_plainText, position); + final int end = WordBreaker.nextBreakIndex(_plainText, position); return [start, end]; } diff --git a/engine/src/flutter/lib/web_ui/lib/src/ui/text.dart b/engine/src/flutter/lib/web_ui/lib/src/ui/text.dart index 10d9f760c1..774787ae64 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/ui/text.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/ui/text.dart @@ -1242,7 +1242,7 @@ abstract class Paragraph { /// on both sides. In such cases, this method will return [offset, offset+1]. /// Word boundaries are defined more precisely in Unicode Standard Annex #29 /// http://www.unicode.org/reports/tr29/#Word_Boundaries - List getWordBoundary(int offset); + List getWordBoundary(dynamic position); /// Returns a list of text boxes that enclose all placeholders in the paragraph. ///