-
Notifications
You must be signed in to change notification settings - Fork 6k
Expose more methods on ui.Paragraph
: lines
#46125
Expose more methods on ui.Paragraph
: lines
#46125
Conversation
8693e6a
to
cf02536
Compare
439dca8
to
7f1329e
Compare
ui.Paragraph
: lines
int? _findLine(int codeUnitOffset, int startLine, int endLine) { | ||
if (endLine <= startLine || codeUnitOffset < lines[startLine].startIndex || lines[endLine - 1].endIndex <= codeUnitOffset) { | ||
return null; | ||
} | ||
if (endLine == startLine + 1) { | ||
return startLine; | ||
} | ||
// endLine >= startLine + 2 thus we have | ||
// startLine + 1 <= midIndex <= endLine - 1 | ||
final int midIndex = (startLine + endLine) ~/ 2; | ||
return _findLine(codeUnitOffset, midIndex, endLine) ?? _findLine(codeUnitOffset, startLine, midIndex); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's code here that does the same thing:
engine/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart
Lines 226 to 232 in 85e1dd9
int i; | |
for (i = 0; i < lines.length - 1; i++) { | |
final ParagraphLine line = lines[i]; | |
if (index >= line.startIndex && index < line.endIndex) { | |
break; | |
} | |
} |
Yours seems to be more performant (because binary search), so it would be nice to use it in getLineBoundary()
.
lib/web_ui/skwasm/text/paragraph.cpp
Outdated
auto metrics = new LineMetrics(); | ||
paragraph->getLineMetricsAt(index, metrics); | ||
return metrics; | ||
return paragraph->getLineMetricsAt(lineNumber, metrics) ? metrics : nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to delete metrics;
in the case where you're returning a nullptr, otherwise this will leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/ui/text/paragraph.cc
Outdated
}; | ||
|
||
Dart_Handle handle = Dart_InvokeClosure( | ||
constructor, sizeof(arguments) / sizeof(Dart_Handle), arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a std::array
for arguments
and call size()
here
hi @eyebrowsoffire I've addressed the comment, could you take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web engine stuff LGTM. Just make sure you get an approval from someone on the native engine side too.
This reverts commit 2805f09.
Reverts #46125 Initiated by: LongCatIsLooong This change reverts the following previous change: Original Description: [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…137743) flutter/engine@eec2ae4...d92ccb9 2023-11-02 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Expose more methods on `ui.Paragraph`: lines" (flutter/engine#47584) 2023-11-02 31859944+LongCatIsLooong@users.noreply.github.com Expose more methods on `ui.Paragraph`: lines (flutter/engine#46125) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.