Length formatter minor fix #66567
Merged
Length formatter minor fix #66567
Conversation
LongCatIsLooong
reviewed
Sep 24, 2020
| // limit or the old value is composing too. | ||
| if (newValue.composing.isValid) { | ||
| if (maxLength != null && maxLength! > 0 && | ||
| oldValue.text.characters.length == maxLength! && |
This caused one of the tests to fail (line 5725 in editable_text_test.dart), when I updated the logic in EditableText:
LongCatIsLooong
reviewed
Sep 24, 2020
| @@ -319,8 +319,8 @@ class LengthLimitingTextInputFormatter extends TextInputFormatter { | |||
| /// The limit on the number of characters (i.e. Unicode scalar values) this formatter | |||
| /// will allow. | |||
| /// | |||
| /// The value must be null or greater than zero. If it is null, then no limit | |||
| /// is enforced. | |||
| /// The value must be null or greater than zero. If it is null or -1, then no | |||
Also @justinmc it appears the docs here talk in length about how we are counting characters in Unicode scalar values. I believe that's no longer true?
Ah good catch. Yeah below it incorrectly says it doesn't count grapheme clusters correctly.
I'll update that in a separate PR right now.
That separate PR is here for the record: #66582
justinmc
approved these changes
Sep 24, 2020
|
|
||
| // The text should not change when trying to insert when the text is already | ||
| // at maxLength. | ||
| state.updateEditingValue(const TextEditingValue(text: '123456', composing: TextRange(start: 5, end: 6))); |
Nit: It could be confusing whether the resulting '12345' is a truncation of '123456' or whether it is the previous value. Maybe use something like 'abcdef' instead of '123456' to make that clear?
Update test case
AlexV525
approved these changes
Sep 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.

Description
Came across this while changing the logic in
EditableText._formatAndSave, the "Length formatter will not cause crash while the TextEditingValue is composing" test fails with those changes. Making this a separate PR.Tests
I added the following tests:
Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.
The text was updated successfully, but these errors were encountered: