Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/ui/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
List<int> 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<int> _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
Expand Down
21 changes: 17 additions & 4 deletions lib/web_ui/lib/src/engine/text/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,26 @@ class EngineParagraph implements ui.Paragraph {
}

@override
List<int> getWordBoundary(int offset) {
List<int> 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 <int>[textPosition.offset, textPosition.offset];
}

final int start = WordBreaker.prevBreakIndex(_plainText, textPosition.offset);
final int end = WordBreaker.nextBreakIndex(_plainText, textPosition.offset);
return <int>[start, end];
}

if (_plainText == null) {
return <int>[offset, offset];
return <int>[position, position];
}

final int start = WordBreaker.prevBreakIndex(_plainText, offset);
final int end = WordBreaker.nextBreakIndex(_plainText, offset);
final int start = WordBreaker.prevBreakIndex(_plainText, position);
final int end = WordBreaker.nextBreakIndex(_plainText, position);
return <int>[start, end];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/ui/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> getWordBoundary(int offset);
List<int> getWordBoundary(dynamic position);

/// Returns a list of text boxes that enclose all placeholders in the paragraph.
///
Expand Down