Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@Amir-P
Copy link
Contributor

@Amir-P Amir-P commented Jul 29, 2023

It fixes an issue in CompositionAwareMixin causing wrong deltas being computed and reported to input clients resulting in wrong state when compositing text in rich text editors like Fleather and possibly others.

Reported deltas on Mac:

TextEditingDeltaInsertion: start: 0, end: 0, data: k
TextEditingDeltaInsertion: start: 1, end: 0, data: y
TextEditingDeltaReplacement: start: 0, end: 2, data: きょ
TextEditingDeltaInsertion: start: 2, end: 0, data: う
TextEditingDeltaInsertion: start: 3, end: 0, data: h
TextEditingDeltaReplacement: start: 0, end: 4, data: きょうは
TextEditingDeltaReplacement: start: 0, end: 4, data: 今日は

Reported deltas on Web (Before):

TextEditingDeltaInsertion: start: 0, end: 0, data: k
TextEditingDeltaInsertion: start: 1, end: 0, data: y
TextEditingDeltaReplacement: start: 0, end: 2, data: きょ
TextEditingDeltaInsertion: start: 2, end: 0, data: う
TextEditingDeltaInsertion: start: 3, end: 0, data: h
TextEditingDeltaReplacement: start: 0, end: 4, data: きょうは
TextEditingDeltaInsertion: start: 4, end: 0, data: 今日は

Reported deltas on Web (After):

TextEditingDeltaInsertion: start: 0, end: 0, data: k
TextEditingDeltaInsertion: start: 1, end: 0, data: y
TextEditingDeltaReplacement: start: 0, end: 2, data: きょ
TextEditingDeltaInsertion: start: 2, end: 0, data: う
TextEditingDeltaInsertion: start: 3, end: 0, data: h
TextEditingDeltaReplacement: start: 0, end: 4, data: きょうは
TextEditingDeltaReplacement: start: 0, end: 4, data: 今日は

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 and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Jul 29, 2023
@Amir-P Amir-P force-pushed the fix/wrong_delta_when_compositing_on_web branch 3 times, most recently from 1963f94 to edc289f Compare August 4, 2023 15:13
@Renzo-Olivares Renzo-Olivares self-requested a review August 8, 2023 20:43
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the delta side of things, thanks for fixing this. cc @mdebbar @htoor3 for any insight/thoughts.

}

final int composingBase = editingState.baseOffset! - composingText!.length;
final int composingBase = editingState.extentOffset! - composingText!.length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me. Using baseOffset fails when composition changes the selection to be non-collapsed, composingBase turns out being negative so (-1,-1) is reported to the framework. This doesn't fail for non-delta input because for non-delta input we always replace the old editing state with the new one, while with delta input we require the correct ranges to correctly infer the difference.


group('determine composition state', () {
test('should return new composition state if valid new composition', () {
test('should return new composition state - compositing middle of text', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably outside of the scope of this PR, but I noticed this test has the selection of the EditingState set to (100, 100), while the text it contains is only testing. The selection should always be in the bounds of the text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@htoor3 htoor3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this change! It looks mostly good, I left a few minor comments

composingExtentOffset: expectedComposingBase + composingText.length));
});

test('should return new composition state - compositing from beginning of text', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! There are some untested code paths in determineCompositionState that we should probably add tests for - mainly the null checks and if composingBase < 0 (will this still occur with this change?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of any scenario that this can happen but it's still possible. Do you think I can address adding tests along with #44139 (comment) in another PR? @htoor3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me @Amir-P

@Amir-P Amir-P force-pushed the fix/wrong_delta_when_compositing_on_web branch from edc289f to 169cb2f Compare August 10, 2023 10:03
@Amir-P Amir-P requested a review from htoor3 August 10, 2023 10:07
@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 14, 2023
@auto-submit auto-submit bot merged commit 785b249 into flutter:main Aug 14, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 14, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 14, 2023
…132522)

flutter/engine@56a0e27...785b249

2023-08-14 amirpanahandeh@yahoo.com Update CompositionAwareMixin to correctly compute composingBase in Web engine (flutter/engine#44139)
2023-08-14 stuartmorgan@google.com Add application:openURLs: forwarding on macOS (flutter/engine#44689)
2023-08-14 skia-flutter-autoroll@skia.org Roll Skia from a4377099b25a to 69ea58157190 (1 revision) (flutter/engine#44692)
2023-08-14 chillers@google.com Update embedder_semantics_update.h imports to include flutter namespace (flutter/engine#44670)
2023-08-14 skia-flutter-autoroll@skia.org Roll Dart SDK from 3295a353980a to d445f5a18876 (1 revision) (flutter/engine#44691)
2023-08-14 dnfield@google.com Revert "Make run_tests.py assert that the ios test dylib is at least as new as libFlutter.dylib" (flutter/engine#44690)
2023-08-14 skia-flutter-autoroll@skia.org Roll Skia from 1cf6f71c8120 to a4377099b25a (1 revision) (flutter/engine#44688)
2023-08-14 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from JKTVoxVrHjZjBaxG4... to uIGMbDkXoIcpqWjgR... (flutter/engine#44687)
2023-08-14 jonahwilliams@google.com [Impeller] Conditionally set command debug info. (flutter/engine#44274)
2023-08-14 kjlubick@users.noreply.github.com Migrate more GL calls of GrBackend* (flutter/engine#44682)

Also rolling transitive DEPS:
  fuchsia/sdk/core/mac-amd64 from JKTVoxVrHjZj to uIGMbDkXoIcp

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC chinmaygarde@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@Amir-P Amir-P deleted the fix/wrong_delta_when_compositing_on_web branch August 15, 2023 04:13
auto-submit bot pushed a commit that referenced this pull request Aug 16, 2023
Adds missing tests for `CompositionAwareMixin`. Check #44139 (comment) and #44139 (comment)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
…b engine (flutter#44139)

It fixes an issue in `CompositionAwareMixin` causing wrong deltas being computed and reported to input clients resulting in wrong state when compositing text in rich text editors like [Fleather](https://github.com/fleather-editor/fleather) and possibly others.

Reported deltas on Mac:
```console
TextEditingDeltaInsertion: start: 0, end: 0, data: k
TextEditingDeltaInsertion: start: 1, end: 0, data: y
TextEditingDeltaReplacement: start: 0, end: 2, data: ��
TextEditingDeltaInsertion: start: 2, end: 0, data: �
TextEditingDeltaInsertion: start: 3, end: 0, data: h
TextEditingDeltaReplacement: start: 0, end: 4, data: ����
TextEditingDeltaReplacement: start: 0, end: 4, data: ���
```

Reported deltas on Web (Before):
```console
TextEditingDeltaInsertion: start: 0, end: 0, data: k
TextEditingDeltaInsertion: start: 1, end: 0, data: y
TextEditingDeltaReplacement: start: 0, end: 2, data: ��
TextEditingDeltaInsertion: start: 2, end: 0, data: �
TextEditingDeltaInsertion: start: 3, end: 0, data: h
TextEditingDeltaReplacement: start: 0, end: 4, data: ����
TextEditingDeltaInsertion: start: 4, end: 0, data: ���
```

Reported deltas on Web (After):
```console
TextEditingDeltaInsertion: start: 0, end: 0, data: k
TextEditingDeltaInsertion: start: 1, end: 0, data: y
TextEditingDeltaReplacement: start: 0, end: 2, data: ��
TextEditingDeltaInsertion: start: 2, end: 0, data: �
TextEditingDeltaInsertion: start: 3, end: 0, data: h
TextEditingDeltaReplacement: start: 0, end: 4, data: ����
TextEditingDeltaReplacement: start: 0, end: 4, data: ���
```

* Fixes flutter/flutter#131335
* Fixes fleather-editor/fleather#150

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong TextEditingDeltas are reported to client writing Japanese - Romaji on Web Typing Japanese alphabet does not yield correct result

3 participants