Skip to content
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

Length formatter minor fix #66567

Merged
merged 3 commits into from Sep 25, 2020

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Sep 24, 2020

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:

  • Length formatter handles composing text correctly, continued

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

// limit or the old value is composing too.
if (newValue.composing.isValid) {
if (maxLength != null && maxLength! > 0 &&
oldValue.text.characters.length == maxLength! &&
Copy link
Contributor Author

@LongCatIsLooong LongCatIsLooong Sep 24, 2020

This caused one of the tests to fail (line 5725 in editable_text_test.dart), when I updated the logic in EditableText:

expect(state.currentTextEditingValue.composing, const TextRange(start: 2, end: 4));

@@ -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
Copy link
Contributor Author

@LongCatIsLooong LongCatIsLooong Sep 24, 2020

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?

Copy link
Contributor

@justinmc justinmc Sep 24, 2020

Ah good catch. Yeah below it incorrectly says it doesn't count grapheme clusters correctly.

Copy link
Contributor

@justinmc justinmc Sep 24, 2020

I'll update that in a separate PR right now.

Copy link
Contributor

@justinmc justinmc Sep 25, 2020

That separate PR is here for the record: #66582

Copy link
Contributor

@justinmc justinmc left a comment

LGTM, good catch. The fix by @AlexV525 in #63754 should still work.


// 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)));
Copy link
Contributor

@justinmc justinmc Sep 24, 2020

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?

Copy link
Member

@AlexV525 AlexV525 left a comment

image

Sometimes jet lag is so bad, that you guys did everything before I woke up... 🤣

@fluttergithubbot fluttergithubbot merged commit c412fd9 into flutter:master Sep 25, 2020
33 checks passed
@LongCatIsLooong LongCatIsLooong deleted the length-formatter-fix branch Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants