This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed
lib/src/engine/skwasm/skwasm_impl Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ class SkwasmLineMetrics extends SkwasmObjectWrapper<RawLineMetrics> implements u
7777
7878 @override
7979 int get lineNumber => lineMetricsGetLineNumber (handle);
80+
81+ int get startIndex => lineMetricsGetStartIndex (handle);
82+ int get endIndex => lineMetricsGetEndIndex (handle);
8083}
8184
8285class SkwasmParagraph extends SkwasmObjectWrapper <RawParagraph > implements ui.Paragraph {
@@ -243,15 +246,13 @@ class SkwasmParagraph extends SkwasmObjectWrapper<RawParagraph> implements ui.Pa
243246
244247 @override
245248 ui.TextRange getLineBoundary (ui.TextPosition position) {
246- final int lineNumber = paragraphGetLineNumberAt (handle, position.offset);
247- final LineMetricsHandle metricsHandle =
248- paragraphGetLineMetricsAtIndex (handle, lineNumber);
249- final ui.TextRange range = ui.TextRange (
250- start: lineMetricsGetStartIndex (metricsHandle),
251- end: lineMetricsGetEndIndex (metricsHandle),
252- );
253- lineMetricsDispose (metricsHandle);
254- return range;
249+ final int offset = position.offset;
250+ for (final SkwasmLineMetrics metrics in computeLineMetrics ()) {
251+ if (offset >= metrics.startIndex && offset <= metrics.endIndex) {
252+ return ui.TextRange (start: metrics.startIndex, end: metrics.endIndex);
253+ }
254+ }
255+ return ui.TextRange .empty;
255256 }
256257
257258 @override
Original file line number Diff line number Diff line change @@ -59,6 +59,19 @@ Future<void> testMain() async {
5959 expect (upstreamWordBoundary, const TextRange (start: 0 , end: 5 ));
6060 });
6161
62+ test ('getLineBoundary at the last character position gives correct results' , () {
63+ final ParagraphBuilder builder = ParagraphBuilder (ParagraphStyle ());
64+ builder.addText ('hello world' );
65+
66+ final Paragraph paragraph = builder.build ();
67+ paragraph.layout (const ParagraphConstraints (width: double .infinity));
68+
69+ final TextRange lineBoundary = paragraph.getLineBoundary (const TextPosition (
70+ offset: 11 ,
71+ ));
72+ expect (lineBoundary, const TextRange (start: 0 , end: 11 ));
73+ });
74+
6275 test ('build and layout a paragraph with an empty addText' , () {
6376 final ParagraphBuilder builder = ParagraphBuilder (ParagraphStyle ());
6477 builder.addText ('' );
You can’t perform that action at this time.
0 commit comments