Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 73b06b7

Browse files
committed
Update APIs to expecte TextRange from getWordBoundary
1 parent b1228c6 commit 73b06b7

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

lib/ui/text.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,12 +1863,19 @@ class Paragraph extends NativeFieldWrapperClass2 {
18631863
}
18641864
List<int> _getPositionForOffset(double dx, double dy) native 'Paragraph_getPositionForOffset';
18651865

1866-
/// Returns the [start, end] of the word at the given offset. Characters not
1867-
/// part of a word, such as spaces, symbols, and punctuation, have word breaks
1868-
/// on both sides. In such cases, this method will return [offset, offset+1].
1866+
/// Returns the [TextRange] of the word at the given [TextPosition.offset].
1867+
///
1868+
/// Characters not part of a word, such as spaces, symbols, and punctuation,
1869+
/// have word breaks on both sides. In such cases, this method will return
1870+
/// `TextRange(begin: position.offset, end: position.offset+1)`.
1871+
///
18691872
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
18701873
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1871-
List<int> getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
1874+
TextRange getWordBoundary(TextPosition position) {
1875+
final List<int> range = _getWordBoundary(position.offset);
1876+
return TextRange(start: range[0], end: range[1]);
1877+
}
1878+
List<int> _getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
18721879

18731880
// Redirecting the paint function in this way solves some dependency problems
18741881
// 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ class EngineParagraph implements ui.Paragraph {
281281
}
282282

283283
@override
284-
List<int> getWordBoundary(int offset) {
284+
ui.TextRange getWordBoundary(ui.TextPosition position) {
285285
if (_plainText == null) {
286-
return <int>[offset, offset];
286+
return ui.TextRange(start: position.offset, end: position.offset);
287287
}
288288

289-
final int start = WordBreaker.prevBreakIndex(_plainText, offset);
290-
final int end = WordBreaker.nextBreakIndex(_plainText, offset);
291-
return <int>[start, end];
289+
final int start = WordBreaker.prevBreakIndex(_plainText, position.offset);
290+
final int end = WordBreaker.nextBreakIndex(_plainText, position.offset);
291+
return ui.TextRange(start: start, end: end);
292292
}
293293

294294
@override

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,12 +1237,15 @@ abstract class Paragraph {
12371237
/// within the text.
12381238
TextPosition getPositionForOffset(Offset offset);
12391239

1240-
/// Returns the [start, end] of the word at the given offset. Characters not
1241-
/// part of a word, such as spaces, symbols, and punctuation, have word breaks
1242-
/// on both sides. In such cases, this method will return [offset, offset+1].
1240+
/// Returns the [TextRange] of the word at the given [TextPosition.offset].
1241+
///
1242+
/// Characters not part of a word, such as spaces, symbols, and punctuation,
1243+
/// have word breaks on both sides. In such cases, this method will return
1244+
/// `TextRange(begin: position.offset, end: position.offset+1)`.
1245+
///
12431246
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
12441247
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1245-
List<int> getWordBoundary(int offset);
1248+
TextRange getWordBoundary(TextPosition position);
12461249

12471250
/// Returns a list of text boxes that enclose all placeholders in the paragraph.
12481251
///

0 commit comments

Comments
 (0)