Create DeltaTextInputClient#90205
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. 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.
Some things to discuss in my comments, but overall I think I like this approach better. We probably shouldn't force implementers of TextInputClient to implement updateEditingValueWithDeltas when most don't care about deltas at all.
| } | ||
|
|
||
| _currentConnection!._client.updateEditingValueWithDeltas(deltas); | ||
| (_currentConnection!._client as DeltaTextInputClient).updateEditingValueWithDeltas(deltas); |
There was a problem hiding this comment.
Is there any risk that _currentConnection!._client might not be a DeltaTextInputClient? Is updateEditingStateWithDeltas ever called on any platform when enableDeltaModel is false? Even if it's not, maybe we need to make it obvious to users in the docs that if they set enableDeltaModel to true, then they must be using an implementation of DeltaTextInputClient and not TextInputClient.
There was a problem hiding this comment.
On the platform side there is no risk. But yes we can add this to the documentation.
There was a problem hiding this comment.
We should add an assert here as well! This is one of the problems with casting things around, it adds risk of misuse. The assert can also include an error message that makes this clear if it is ever encountered.
There was a problem hiding this comment.
I don't think we can accomplish this same thing without breaking the interface API though, so reluctantly, we may have to proceed with something like this even though it is a bit awkward
There was a problem hiding this comment.
That's right. If a platform implements the delta model, and someone is using a TextInputClient with a TextInputConfiguration with enableDeltaModel set to true then they will be able to reach this case and receive unexpected behavior.
There was a problem hiding this comment.
Ok, well let's slap tons of warnings and docs and asserts around this to make sure it is at least obvious exactly how to fix it/make it work. Kind of ugly but the cost of being non-breaking.
There was a problem hiding this comment.
If this were not an opt-in feature, im tempted to just break as most developers using this would be advanced anyways and it should be trivial to copy-paste in a snipped already included in the docs, but I don't think we should break people especially if they don't even need it for their code to keep working.
| value = delta.apply(value); | ||
| } | ||
| updateEditingValue(value); | ||
| } |
There was a problem hiding this comment.
Since we're losing this method, should we include it as an example implementation of updateEditingValueWithDeltas in the docs or something? I want to make sure that users know what to do here when they implement updateEditingValueWithDeltas.
There was a problem hiding this comment.
That makes sense to me! Don't see why an example would hurt.
|
|
||
| /// An interface to receive information from [TextInput]. | ||
| /// | ||
| /// If [TextInputConfiguration.enableDeltaModel] is set to true you should |
There was a problem hiding this comment.
Nit wording: ... is set to true, [DeltaTextInputClient] must be implemented instead of this class.
| /// * [TextInput.attach] | ||
| /// * [EditableText], a [TextInputClient] implementation. | ||
| /// * [DeltaTextInputClient], a [TextInputClient] extension that receives | ||
| /// granular information from the platform's text input. |
| _currentConnection!._client.updateEditingValue(TextEditingValue.fromJSON(args[1] as Map<String, dynamic>)); | ||
| break; | ||
| case 'TextInputClient.updateEditingStateWithDeltas': | ||
| assert(_currentConnection!._client is DeltaTextInputClient, 'You should be using a DeltaTextInputClient if you have TextInputConfiguration.enableDeltaModel set to true'); |
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍 , just two nits.
| /// | ||
| /// Here is an example of what implementation of this method could look like: | ||
| /// | ||
| /// @override |
There was a problem hiding this comment.
This example should probably be a {@tool snippet} so that it's formatted nicely on the docs website.
| TextInputConfiguration get configuration => const TextInputConfiguration(enableDeltaModel: true); | ||
| } | ||
|
|
||
| class FakeTextChannel implements MethodChannel { |
There was a problem hiding this comment.
Nit: Is this identical to the one in text_input_test.dart? Could the code be shared somehow? Maybe a text_input_utils.dart file or something.
There was a problem hiding this comment.
Yeah it's shared by autofill_test.dart and text_input_test.dart so i'll make it a common file.
justinmc
left a comment
There was a problem hiding this comment.
LGTM with the changes 👍
Description
Fixes b/200138301
Looks like there are some failures for those who implement
TextInputClient. They are missing anupdateEditingValueWithDeltasimplementation. This change aims to fix this by instead of addingupdateEditingValueWithDeltastoTextInputClientinterface, we extendTextInputClientand add the new method in there. This extension will be calledDeltaTextInputClient.With this change we do not force people who do not want any deltas to implement
updateEditingValueWithDeltas.Related Issues
Fixes b/200138301
Tests
Added tests to verify
updateEditingValueWithDeltasmethod is called.Adds a
text_input_utils.dartfor the commonFakeTextChannelto be shared.Pre-launch Checklist
///).