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

Commit c001f10

Browse files
committed
Add web API
1 parent 31f7bf8 commit c001f10

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ class EngineParagraph implements ui.Paragraph {
291291
return <int>[start, end];
292292
}
293293

294+
@override
295+
List<int> getLineBoundary(int offset) {
296+
// TODO(flutter_web): https://github.com/flutter/flutter/issues/39537
297+
// Depends upon LineMetrics measurement.
298+
return null;
299+
}
300+
294301
@override
295302
List<ui.LineMetrics> computeLineMetrics() {
296303
// TODO(flutter_web): https://github.com/flutter/flutter/issues/39537

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,8 @@ class LineMetrics {
10271027
this.left,
10281028
this.baseline,
10291029
this.lineNumber,
1030+
this.startIndex,
1031+
this.endIndex,
10301032
});
10311033

10321034
@pragma('vm:entry-point')
@@ -1040,6 +1042,8 @@ class LineMetrics {
10401042
this.left,
10411043
this.baseline,
10421044
this.lineNumber,
1045+
this.startIndex,
1046+
this.endIndex,
10431047
);
10441048

10451049
final bool hardBreak;
@@ -1059,6 +1063,10 @@ class LineMetrics {
10591063
final double baseline;
10601064

10611065
final int lineNumber;
1066+
1067+
final int startIndex;
1068+
1069+
final int endIndex;
10621070
}
10631071

10641072
/// A paragraph of text.
@@ -1160,6 +1168,16 @@ abstract class Paragraph {
11601168
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
11611169
List<int> getWordBoundary(int offset);
11621170

1171+
/// Returns the [start, end] of the line at the given offset.
1172+
///
1173+
/// The newline (if any) is returned as part of the range.
1174+
///
1175+
/// This can potentially be expensive, since it needs to compute the line
1176+
/// metrics, so use it sparingly. If higher performance is needed, caching the
1177+
/// results of [computeLineMetrics] is recommended (which also contains the
1178+
/// start and end of each line).
1179+
List<int> getLineBoundary(int offset);
1180+
11631181
/// Returns a list of text boxes that enclose all placeholders in the paragraph.
11641182
///
11651183
/// The order of the boxes are in the same order as passed in through [addPlaceholder].

0 commit comments

Comments
 (0)