-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add Spell Check to EditableText #104460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Spell Check to EditableText #104460
Conversation
|
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. |
justinmc
left a comment
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.
The approach looks good, just some small nits and questions mostly.
justinmc
left a comment
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 👍
justinmc
left a comment
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.
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!
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.
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?
dev/integration_tests/spell_check/integration_test/integration_test.dart
Outdated
Show resolved
Hide resolved
dev/integration_tests/spell_check/integration_test/integration_test.dart
Outdated
Show resolved
Hide resolved
dev/integration_tests/spell_check/integration_test/integration_test.dart
Outdated
Show resolved
Hide resolved
dev/integration_tests/spell_check/integration_test/integration_test.dart
Outdated
Show resolved
Hide resolved
justinmc
left a comment
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.
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.
justinmc
left a comment
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.
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.
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.
Also if spellCheckConfiguration is null itself then spell check is disabled, right? Maybe consider mentioning that here.
justinmc
left a comment
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.
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.
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.
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.
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.
@cyanglaz I would also like confirmation of this. I've been using flutter upgrade-packages as per an error message I got.
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.
I thought that last sentence of this paragraph is false? spellCheckService and spellCheckSuggestionsHandler will get default values if they are null.
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.
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.
justinmc
left a comment
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.
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?
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.
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.
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.
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.
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.
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.
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.
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.
d546ab4 to
f077da7
Compare
…tter#109315)" This reverts commit f077da7.
…on) (flutter#109315)"" This reverts commit 3959e80.
This reverts commit 3162134.
| fonts: | ||
| - asset: packages/flutter_gallery_assets/fonts/GalleryIcons.ttf | ||
|
|
||
| <<<<<<< HEAD |
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.
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 |
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.
Here too
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
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.