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

Commit a37e27b

Browse files
authored
[web] Don't include end-of-line characters in line boundary (#39693)
1 parent 1d7f0c6 commit a37e27b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class CanvasParagraph implements ui.Paragraph {
237237
}
238238

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

243243
@override

lib/web_ui/test/text/canvas_paragraph_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@ Future<void> testMain() async {
700700
for (int i = 0; i < 11; i++) {
701701
expect(
702702
paragraph.getLineBoundary(ui.TextPosition(offset: i)),
703-
const ui.TextRange(start: 0, end: 11),
703+
// The "\n" is not included in the line boundary.
704+
const ui.TextRange(start: 0, end: 10),
704705
reason: 'failed at offset $i',
705706
);
706707
}
@@ -709,7 +710,8 @@ Future<void> testMain() async {
709710
for (int i = 11; i < 23; i++) {
710711
expect(
711712
paragraph.getLineBoundary(ui.TextPosition(offset: i)),
712-
const ui.TextRange(start: 11, end: 23),
713+
// The "\n" is not included in the line boundary.
714+
const ui.TextRange(start: 11, end: 22),
713715
reason: 'failed at offset $i',
714716
);
715717
}

0 commit comments

Comments
 (0)