Sitelet https://github.com/flutter/flutter/pull/97437
Skip to content

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

Merged
fluttergithubbot merged 1 commit into
flutter:masterfrom
twinsunllc:reland-scribble-2
Feb 1, 2022
Merged

fluttergithubbot merged 1 commit into
flutter:masterfrom
twinsunllc:reland-scribble-2

Conversation

@fbcouch

@fbcouch fbcouch commented Jan 28, 2022

Copy link
Copy Markdown
Contributor

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 p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Jan 28, 2022

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

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

fbcouch commented Jan 31, 2022

Copy link
Copy Markdown
Contributor Author

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

@justinmc

justinmc commented Feb 1, 2022

Copy link
Copy Markdown
Contributor

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

flar commented Feb 2, 2022 •

Copy link
Copy Markdown
Contributor

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

justinmc commented Feb 2, 2022

Copy link
Copy Markdown
Contributor

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

flar commented Feb 2, 2022 •

Copy link
Copy Markdown
Contributor

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

@justinmc

justinmc commented Feb 3, 2022

Copy link
Copy Markdown
Contributor

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

flar commented Feb 3, 2022

Copy link
Copy Markdown
Contributor

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

@LongCatIsLooong

LongCatIsLooong commented Feb 3, 2022 •

Copy link
Copy Markdown
Contributor

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

flar commented Feb 3, 2022

Copy link
Copy Markdown
Contributor

The regression has been triaged. Thanks all!

@justinmc

justinmc commented Feb 3, 2022

Copy link
Copy Markdown
Contributor

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 framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField should support apple pencil input by default.

5 participants