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

Commit aa46dd5

Browse files
committed
Revert API change, just land TextRange addition.
1 parent 100215f commit aa46dd5

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

lib/ui/text.dart

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,9 @@ class TextRange {
14131413
/// The [start] and [end] arguments must not be null. Both the [start] and
14141414
/// [end] must either be greater than or equal to zero or both exactly -1.
14151415
///
1416+
/// The text included in the range includes the character at [start], but not
1417+
/// the one at [end].
1418+
///
14161419
/// Instead of creating an empty text range, consider using the [empty]
14171420
/// constant.
14181421
const TextRange({
@@ -1596,8 +1599,8 @@ enum BoxHeightStyle {
15961599
/// Defines various ways to horizontally bound the boxes returned by
15971600
/// [Paragraph.getBoxesForRange].
15981601
enum BoxWidthStyle {
1599-
// Provide tight bounding boxes that fit widths to the runs of each line
1600-
// independently.
1602+
/// Provide tight bounding boxes that fit widths to the runs of each line
1603+
/// independently.
16011604
tight,
16021605

16031606
/// Adds up to two additional boxes as needed at the beginning and/or end
@@ -1863,19 +1866,12 @@ class Paragraph extends NativeFieldWrapperClass2 {
18631866
}
18641867
List<int> _getPositionForOffset(double dx, double dy) native 'Paragraph_getPositionForOffset';
18651868

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-
///
1869+
/// Returns the [start, end] of the word at the given offset. Characters not
1870+
/// part of a word, such as spaces, symbols, and punctuation, have word breaks
1871+
/// 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-
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';
1874+
List<int> getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
18791875

18801876
// Redirecting the paint function in this way solves some dependency problems
18811877
// 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-
ui.TextRange getWordBoundary(ui.TextPosition position) {
284+
List<int> getWordBoundary(int offset) {
285285
if (_plainText == null) {
286-
return ui.TextRange(start: position.offset, end: position.offset);
286+
return <int>[offset, offset];
287287
}
288288

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);
289+
final int start = WordBreaker.prevBreakIndex(_plainText, offset);
290+
final int end = WordBreaker.nextBreakIndex(_plainText, offset);
291+
return <int>[start, end];
292292
}
293293

294294
@override

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

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

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-
///
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].
12461243
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
12471244
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1248-
TextRange getWordBoundary(TextPosition position);
1245+
List<int> getWordBoundary(int offset);
12491246

12501247
/// Returns a list of text boxes that enclose all placeholders in the paragraph.
12511248
///

0 commit comments

Comments
 (0)