Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Re-land "Support Scribble Handwriting" (#96615) #97437

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

Merged
merged 1 commit into from
Feb 1, 2022

Conversation

fbcouch
Copy link
Contributor

@fbcouch fbcouch commented Jan 28, 2022

Reverts #97405

@LongCatIsLooong @justinmc

Fixes #61278

Original PR #75472

Migration Guide: https://github.com/flutter/website/blob/main/src/release/breaking-changes/scribble-text-input-client.md

It looks like the migration to SkParagraph very slightly changed the results of renderEditable.getBoxesForSelection so that placeholders are now included, but have an empty list. Here's the change to accommodate the difference:

diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart
index 3064b9cee7..f91e9e61de 100644
--- a/packages/flutter/lib/src/widgets/editable_text.dart
+++ b/packages/flutter/lib/src/widgets/editable_text.dart
@@ -2728,7 +2728,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
     if (WidgetsBinding.instance!.window.physicalSize.shortestSide < _kIPadWidth)
       return;
 
-    final String text = renderEditable.text?.toPlainText(includeSemanticsLabels: false, includePlaceholders: false) ?? '';
+    final String text = renderEditable.text?.toPlainText(includeSemanticsLabels: false) ?? '';
     final List<Rect> firstSelectionBoxes = renderEditable.getBoxesForSelection(const TextSelection(baseOffset: 0, extentOffset: 1));
     final Rect? firstRect = firstSelectionBoxes.isNotEmpty ? firstSelectionBoxes.first : null;
     final ScrollDirection scrollDirection = _scrollController.position.userScrollDirection;
@@ -2752,8 +2752,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
             return null;
 
           final int offset = _cachedText.characters.getRange(0, i).string.length;
+          final List<Rect> boxes = renderEditable.getBoxesForSelection(TextSelection(baseOffset: offset, extentOffset: offset + _cachedText.characters.characterAt(i).string.length));
+          if (boxes.isEmpty)
+            return null;
+
           final SelectionRect selectionRect = SelectionRect(
-            bounds: renderEditable.getBoxesForSelection(TextSelection(baseOffset: offset, extentOffset: offset + _cachedText.characters.characterAt(i).string.length)).first,
+            bounds: boxes.first,
             position: offset,
           );
           if (renderEditable.paintBounds.bottom < selectionRect.bounds.top) {

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 a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 28, 2022
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 👍

Thanks for the diff of the change to fix the tests.

@fbcouch
Copy link
Contributor Author

fbcouch commented Jan 31, 2022

@LongCatIsLooong @justinmc Think we can try landing this again?

@justinmc
Copy link
Contributor

justinmc commented Feb 1, 2022

Looks like the build succeeded for this 👍 . Let's continue to keep an eye out and make sure that nothing is broken internally by these changes.

@flar
Copy link
Contributor

flar commented Feb 2, 2022

Our benchmarks that monitor web deployment sizes saw a very small increase due to this feature, but I imagine that is to be expected and within reason for this feature?

https://flutter-flutter-perf.skia.org/e/?begin=1643716522&end=1643740360&keys=X2ae1480879add9e7079b55d2f713c856&num_commits=50&request_type=1&xbaroffset=27379

@justinmc @LongCatIsLooong

@justinmc
Copy link
Contributor

justinmc commented Feb 2, 2022

I was not expecting a size increase from this PR (or the engine PR), but maybe I've forgotten something that @LongCatIsLooong or @fbcouch would know? Each PR is only +~1,200 lines.

Looking at the code, I see that this PR is using StringCharacters from the characters package for the first time (line), would that do it? Elsewhere we import the entire characters package, but I don't think we've referenced StringCharacters before, maybe it was being tree-shaken out before this?

@flar
Copy link
Contributor

flar commented Feb 2, 2022

The increase is around 12kb uncompressed or 4kb compressed which is around .4% in each case.

@justinmc
Copy link
Contributor

justinmc commented Feb 3, 2022

Did you mean kb? I wouldn't expect this to increase the size of any APK by 12mb even if it is the StringCharacters thing.

@flar
Copy link
Contributor

flar commented Feb 3, 2022

Sorry, I think you're right. I'll edit my comment.

@LongCatIsLooong
Copy link
Contributor

LongCatIsLooong commented Feb 3, 2022

I was not expecting a size increase from this PR (or the engine PR), but maybe I've forgotten something that @LongCatIsLooong or @fbcouch would know? Each PR is only +~1,200 lines.

Looking at the code, I see that this PR is using StringCharacters from the characters package for the first time (line), would that do it? Elsewhere we import the entire characters package, but I don't think we've referenced StringCharacters before, maybe it was being tree-shaken out before this?

Yeah looks like the characters package itself defined a relatively large const string here: https://github.com/dart-lang/characters/blob/master/lib/src/grapheme_clusters/table.dart. If this becomes part of the binary then I wouldn't be too surprised that there's a 4kb increase. We'll probably need to use that library in more places in the future so it's just a matter of time for the size increase to happen.

@flar
Copy link
Contributor

flar commented Feb 3, 2022

The regression has been triaged. Thanks all!

@justinmc
Copy link
Contributor

justinmc commented Feb 3, 2022

Ah got it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository 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.

TextField should support apple pencil input by default.
5 participants