Skip to content

Conversation

@camsim99
Copy link
Contributor

@camsim99 camsim99 commented May 23, 2022

This PR is intended to add the APIs used to support spell check for EditableText, as part of Issue #34688.

To understand this PR in fuller context, please see this proof of concept PR. Note that this PR will not be landed on its own.

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, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label May 23, 2022
@camsim99 camsim99 marked this pull request as ready for review May 25, 2022 23:30
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

The approach looks good, just some small nits and questions mostly.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

The integration tests are really good, thanks for adding them.

There are a bunch of cases where closing parenthesis should be on the following line, something like this:

myFunction(
  veryLongParametersThatWouldntAllFitOnOneLine,
);

I could be wrong but I think that's part of the Flutter styleguide.

Otherwise mostly minor comments, looking good!

Copy link
Contributor

Choose a reason for hiding this comment

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

In the main repo this should be formatted like this:

expect(
  spellCheckSuggestionSpans!.length,
  equals(misspelledWordRanges.length),
);

And same for several other places where the closing parenthesis is on the same line but should be on the next line.

Maybe this kind of stuff is not enforced in integration_tests though?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Some thoughts on the organization of the platform-specific styles in relation to the Cupertino and Material libraries. This is kind of a high-level idea, so let me know if it doesn't work out the way I'm hoping it will.

@camsim99 camsim99 changed the title Add Spell Check APIs Add Spell Check to EditableText Jul 7, 2022
@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jul 7, 2022
@camsim99 camsim99 requested review from justinmc and removed request for blasten July 15, 2022 18:50
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Overall looks good, I think this is almost ready.

I like default setup we discussed, with the spellCheckConfiguration's default set when passed to EditableText. It's not ideal but it's pretty typical and intuitive, shouldn't be a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also if spellCheckConfiguration is null itself then spell check is disabled, right? Maybe consider mentioning that here.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

The main thing I found in my review was what I think is a bug due to not updating the SpellCheckConfiguration in didUpdateWidget (see comment below). Otherwise mostly small stuff.

The defaulting for SpellCheckConfiguration that we were talking about all looks fine to me now, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the way that we typically update all of these pubspec.yamls and everything? Maybe @cyanglaz knows? I just want to double check that it's ok/normal to check in all of these pubspec.yaml updates when modifying the integration tests and stuff. Some of them seem like they might be unrelated to this PR, if it matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cyanglaz I would also like confirmation of this. I've been using flutter upgrade-packages as per an error message I got.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that last sentence of this paragraph is false? spellCheckService and spellCheckSuggestionsHandler will get default values if they are null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment was to address your comment above, which is to note that if the configuration itself is left null, then spell check will be disabled, which is true. That will change when spell check is enabled by default, though.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Making SpellCheckSuggestionsHandler private seems to have simplified things. I left a comment that maybe it can be fully static, but otherwise that looks like a pretty good improvement.

What would actually happen if someone passed in a SpellCheckConfiguration to their text field after this PR is merged? The spell check would occur and the word would be underlined, but no menu would appear?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be derived from the state rather than saved? For example, maybe this could be a getter that looks at widget.spellCheckConfiguration to determine its return value. That way we don't have to worry about this value ever being out of sync with widget.spellCheckConfiguration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, the linter throws avoid_classes_with_only_static_members. I played around with moving this code completely to EditableTextState but it felt wonky, since it would be harder for users to access these methods (since keeping them static would not make sense anymore) and it would also be weirder to test. Thought about moving it to one of the SpellCheckConfiguration or SpellCheckResults classes but neither seemed fitting. Also, I think that moving this code out of this class would further commit us to not allowing this handler to be configurable, and I don't believe that is desirable.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if you get rid of the class and just make these top level functions? Kind of like showMenu I guess.

What are you goals for making this configurable as you say? Currently buildTextSpanWithSpellCheckSuggestions can be reused in places other than EditableText (maybe like a custom text editor?) but EditableText's usage of it can't be configured.

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 think making them top level functions makes sense. I actually was pro-moving them out of their own class 😅 I think I just overthought the impact of moving the methods out of their own class.

@jmagman jmagman removed their request for review August 10, 2022 17:47
fonts:
- asset: packages/flutter_gallery_assets/fonts/GalleryIcons.ttf

<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a leftover merge artifact. It looks like it is causing several of the test failures

- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Regular.ttf
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Light.ttf

<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.