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

Expose more methods on ui.Paragraph: lines #46125

Merged
merged 13 commits into from
Nov 2, 2023

Conversation

LongCatIsLooong
Copy link
Contributor

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Sep 20, 2023
@LongCatIsLooong LongCatIsLooong changed the title Paragraph api lines Expose more methods on ui.Paragraph: lines Sep 21, 2023
@LongCatIsLooong LongCatIsLooong marked this pull request as ready for review September 21, 2023 03:56
Comment on lines +256 to +267
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);
}
Copy link
Contributor

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:

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().

auto metrics = new LineMetrics();
paragraph->getLineMetricsAt(index, metrics);
return metrics;
return paragraph->getLineMetricsAt(lineNumber, metrics) ? metrics : nullptr;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@jason-simmons jason-simmons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

};

Dart_Handle handle = Dart_InvokeClosure(
constructor, sizeof(arguments) / sizeof(Dart_Handle), arguments);
Copy link
Member

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

@LongCatIsLooong
Copy link
Contributor Author

hi @eyebrowsoffire I've addressed the comment, could you take another look?

Copy link
Contributor

@eyebrowsoffire eyebrowsoffire left a 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.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 2, 2023
@auto-submit auto-submit bot merged commit 2805f09 into flutter:main Nov 2, 2023
flar added a commit that referenced this pull request Nov 2, 2023
@LongCatIsLooong LongCatIsLooong added the revert Label used to revert changes in a closed and merged pull request. label Nov 2, 2023
auto-submit bot pushed a commit that referenced this pull request Nov 2, 2023
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Nov 2, 2023
auto-submit bot added a commit that referenced this pull request Nov 2, 2023
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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 2, 2023
@LongCatIsLooong LongCatIsLooong deleted the paragraph-api-lines branch November 2, 2023 02:16
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 2, 2023
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants