Skip to content

Commit c183e59

Browse files
authored
Revert "[web] Fix edge cases in Paragraph.getPositionForOffset to match Flutter (flutter#16557)"
This reverts commit 7a6d978.
1 parent d46d86a commit c183e59

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ class DomTextMeasurementService extends TextMeasurementService {
429429
text,
430430
startIndex: 0,
431431
endIndex: text.length,
432-
endIndexWithoutNewlines:
433-
_excludeTrailing(text, 0, text.length, _newlinePredicate),
434432
hardBreak: true,
435433
width: lineWidth,
436434
left: alignOffset,
@@ -798,8 +796,6 @@ class LinesCalculator {
798796
_text.substring(_lineStart, breakingPoint) + _style.ellipsis,
799797
startIndex: _lineStart,
800798
endIndex: chunkEnd,
801-
endIndexWithoutNewlines:
802-
_excludeTrailing(_text, _chunkStart, chunkEnd, _newlinePredicate),
803799
hardBreak: false,
804800
width: widthOfResultingLine,
805801
left: alignOffset,
@@ -865,7 +861,6 @@ class LinesCalculator {
865861
_text.substring(_lineStart, endWithoutNewlines),
866862
startIndex: _lineStart,
867863
endIndex: lineEnd,
868-
endIndexWithoutNewlines: endWithoutNewlines,
869864
hardBreak: isHardBreak,
870865
width: lineWidth,
871866
left: alignOffset,

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ class EngineLineMetrics implements ui.LineMetrics {
1717
this.lineNumber,
1818
}) : text = null,
1919
startIndex = -1,
20-
endIndex = -1,
21-
endIndexWithoutNewlines = -1;
20+
endIndex = -1;
2221

2322
EngineLineMetrics.withText(
2423
this.text, {
2524
@required this.startIndex,
2625
@required this.endIndex,
27-
@required this.endIndexWithoutNewlines,
2826
@required this.hardBreak,
2927
this.ascent,
3028
this.descent,
@@ -35,9 +33,6 @@ class EngineLineMetrics implements ui.LineMetrics {
3533
this.baseline,
3634
@required this.lineNumber,
3735
}) : assert(text != null),
38-
assert(startIndex != null),
39-
assert(endIndex != null),
40-
assert(endIndexWithoutNewlines != null),
4136
assert(hardBreak != null),
4237
assert(width != null),
4338
assert(left != null),
@@ -55,10 +50,6 @@ class EngineLineMetrics implements ui.LineMetrics {
5550
/// the text and doesn't stop at the overflow cutoff.
5651
final int endIndex;
5752

58-
/// The index (exclusive) in the text where this line ends, ignoring newline
59-
/// characters.
60-
final int endIndexWithoutNewlines;
61-
6253
@override
6354
final bool hardBreak;
6455

@@ -425,7 +416,7 @@ class EngineParagraph implements ui.Paragraph {
425416
// [offset] is to the right of the line.
426417
if (offset.dx >= lineRight) {
427418
return ui.TextPosition(
428-
offset: lineMetrics.endIndexWithoutNewlines,
419+
offset: lineMetrics.endIndex,
429420
affinity: ui.TextAffinity.upstream,
430421
);
431422
}
@@ -438,7 +429,7 @@ class EngineParagraph implements ui.Paragraph {
438429
final TextMeasurementService instance = _measurementService;
439430

440431
int low = lineMetrics.startIndex;
441-
int high = lineMetrics.endIndexWithoutNewlines;
432+
int high = lineMetrics.endIndex;
442433
do {
443434
final int current = (low + high) ~/ 2;
444435
final double width = instance.measureSubstringWidth(this, lineMetrics.startIndex, current);

lib/web_ui/test/paragraph_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void main() async {
199199
builder.addText('abcdefg\n');
200200
builder.addText('ab');
201201
final Paragraph paragraph = builder.build();
202-
paragraph.layout(const ParagraphConstraints(width: 100));
202+
paragraph.layout(const ParagraphConstraints(width: 1000));
203203

204204
// First line: "abcd\n"
205205

@@ -216,7 +216,7 @@ void main() async {
216216
// At the end of the first line.
217217
expect(
218218
paragraph.getPositionForOffset(Offset(50, 5)),
219-
TextPosition(offset: 4, affinity: TextAffinity.upstream),
219+
TextPosition(offset: 5, affinity: TextAffinity.upstream),
220220
);
221221
// On the left side of "b" in the first line.
222222
expect(
@@ -239,7 +239,7 @@ void main() async {
239239
// At the end of the second line.
240240
expect(
241241
paragraph.getPositionForOffset(Offset(100, 15)),
242-
TextPosition(offset: 12, affinity: TextAffinity.upstream),
242+
TextPosition(offset: 13, affinity: TextAffinity.upstream),
243243
);
244244
// On the left side of "e" in the second line.
245245
expect(
@@ -261,7 +261,7 @@ void main() async {
261261
);
262262
// At the end of the last line.
263263
expect(
264-
paragraph.getPositionForOffset(Offset(100, 25)),
264+
paragraph.getPositionForOffset(Offset(40, 25)),
265265
TextPosition(offset: 15, affinity: TextAffinity.upstream),
266266
);
267267
// Below the last line.

0 commit comments

Comments
 (0)