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

Conversation

@gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Nov 7, 2019

This exposes the line boundary information a line by adding getLineBoundary to return the indices corresponding to a line around a TextPosition. The information is already calculated when calculating line metrics, so that we can enable moving the selection/cursor to the beginning/end of a line in a text field.

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Web changes look good to me as long as regular text field functionality doesn't regress on flutter web.

@GaryQian
Copy link
Contributor

GaryQian commented Nov 7, 2019

cc @Hixie

The reason we did not include this in the initial version of LineMetrics is due to likely future changes away from utf16 codepoints to represent chars, instead relying on dart's representation.

I'd run this through Ian first.

@GaryQian
Copy link
Contributor

GaryQian commented Nov 7, 2019

cc @a-siva What is the status of any work on a new dart-string/unicode system?

@Hixie
Copy link
Contributor

Hixie commented Nov 7, 2019

I don't think we should add this yet, because we don't want to be adding yet more APIs that add to our String API technical debt.

Specifically, this API as defined would mean that this uses a different meaning for indices into strings than does String.indexOf et al. But, if we were to make it the same, it would mean that we were using UTF-16 words as indices in this API, which is a terrible technical choice.

@Hixie
Copy link
Contributor

Hixie commented Nov 7, 2019

(If we did want to land this, we should make sure to implement it on Web before landing. We are at a point where it is no longer OK to only implement things on some platforms.)

@gspencergoog
Copy link
Contributor Author

gspencergoog commented Nov 7, 2019

OK, but this will mean that we don't have line selection or line-by-line cursor movement in desktop keyboard editing. I'll remove that capability from flutter/flutter#44130 and file a bug to implement it someday when we have real line metrics.

NB: I did talk to Mouad to ask if I needed to implement it on web, and we decided that I didn't, because this API won't be used on the web anyhow, since text field editing is handled by the browser.

@gspencergoog
Copy link
Contributor Author

Actually I spoke with Ian, and we have an idea of how to implement this without adding as much technical debt, so reopening.

@gspencergoog gspencergoog reopened this Nov 8, 2019
@Hixie
Copy link
Contributor

Hixie commented Nov 8, 2019

Ok well we do need line-by-line cursor movement.

Greg and I spoke in person. I suggested that we move TextRange from services to dart:ui and return that from the relevant APIs here. That way, we reduce this to a previously unsolved problem rather than adding any new technical debt.

Also, we should test that this is all working in UTF-16 code units and not Unicode code points.

@gspencergoog
Copy link
Contributor Author

I'll make a separate PR for moving TextRange into dart:ui, since that's a breaking change.

@gspencergoog
Copy link
Contributor Author

Here's the PR for moving TextRange: #13747

final List<int> boundary = _getLineBoundary(position.offset);
return TextRange(start: boundary[0], end: boundary[1]);
}
List<int> _getLineBoundary(int offset) native 'Paragraph_getLineBoundary';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this is implemented in C++ and not in Dart directly? (Implementing it in Dart would reduce unnecessary work since web can also use the same implementation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have the history on why that is, but I assume the reason is that we didn't want to have to implement, test, and maintain the code, and it already existed in the text library. If that's the case, then I suspect that with the advent of web, it makes sense to make the investment and implement, test, and maintain it (since we'll need to do that anyhow for web).

It's possible that it is somehow linked to the text processing library that we use, though, so I'll defer to the engine team on that.

cc/ @jason-simmons @GaryQian

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, it would be far more efficient to compute it in C++ instead of serializing and passing all the LineMetrics to dart, decoding, and processing it there.

This also keeps implementations consistent throughout the Paragraph API. Methods such as GetRectsForRange requires a significant computation that can only be done at engine level, and splitting implementation between dart and C++ would make it harder to maintain.

gspencergoog added a commit to flutter/flutter that referenced this pull request Nov 11, 2019
Convert the call to getWordBoundary to use a TextPosition, in preparation for landing flutter/engine#13727, which switches the desired API to the final desired API.
///
/// The newline (if any) is returned as part of the range.
///
/// This can potentially be expensive, since it needs to compute the line
Copy link
Contributor

Choose a reason for hiding this comment

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

The line metrics are computed as part of layout, so as long as it is used after layout, this should not be particularly expensive. We currently don't do any additional computation beyond that of layout to calculate the LineMetrics.

What should be mentioned though is that this is invalid before layout.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this warning can remain, as it depends on the implementation. Web or SkShaper may have more expensive implementations. It just so happens LibTxt computes this in layout.

Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

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

LGTM, minor nit.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 12, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 12, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 12, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 12, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 12, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants