Skip to content

Commit

Permalink
[web] Don't include end-of-line characters in line boundary (flutter#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdebbar authored Feb 17, 2023
1 parent 1d7f0c6 commit a37e27b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/text/canvas_paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class CanvasParagraph implements ui.Paragraph {
}

final ParagraphLine line = lines[i];
return ui.TextRange(start: line.startIndex, end: line.endIndex);
return ui.TextRange(start: line.startIndex, end: line.endIndex - line.trailingNewlines);
}

@override
Expand Down
6 changes: 4 additions & 2 deletions lib/web_ui/test/text/canvas_paragraph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,8 @@ Future<void> testMain() async {
for (int i = 0; i < 11; i++) {
expect(
paragraph.getLineBoundary(ui.TextPosition(offset: i)),
const ui.TextRange(start: 0, end: 11),
// The "\n" is not included in the line boundary.
const ui.TextRange(start: 0, end: 10),
reason: 'failed at offset $i',
);
}
Expand All @@ -709,7 +710,8 @@ Future<void> testMain() async {
for (int i = 11; i < 23; i++) {
expect(
paragraph.getLineBoundary(ui.TextPosition(offset: i)),
const ui.TextRange(start: 11, end: 23),
// The "\n" is not included in the line boundary.
const ui.TextRange(start: 11, end: 22),
reason: 'failed at offset $i',
);
}
Expand Down

0 comments on commit a37e27b

Please sign in to comment.