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

[Web] Fix insertions/deletions at inverted selection for TextEditingDeltas #44693

Merged
merged 10 commits into from Sep 8, 2023

Conversation

Renzo-Olivares
Copy link
Contributor

Fixes issue where the delta range would be calculated wrong when the selection is inverted.

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 Aug 14, 2023
final List<dynamic> eventArgs = <dynamic>[
'beforeinput',
js_util.jsify(<String, dynamic>{
'inputType': 'insertLineBreak',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdebbar This test currently fails because there is no DomInputEvent defined for InputEvent which contains inputType. In handleBeforeInput we check the inputType in the logic. Is there a way to test this?

Copy link
Member

Choose a reason for hiding this comment

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

PR to fix the tests: Renzo-Olivares#87

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the fix! I was trying to avoid adding to the DOM API but if that's the only way to test this I think its okay. InputEvent is a basic building block like KeyboardEvent and other related events so it would be good to add.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. It seems to me that extending DOM bindings where needed is better than ad-hoc wrapper just for the test.

@@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:js_interop';
Copy link
Member

Choose a reason for hiding this comment

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

Seems causing the CI check to fail.

@Renzo-Olivares
Copy link
Contributor Author

cc @htoor3 @mdebbar for feedback/thoughts.

@htoor3
Copy link
Contributor

htoor3 commented Aug 23, 2023

Thank you for this change @Renzo-Olivares!

There appear to be a few linting errors

warning - lib/src/engine/text_editing/text_editing.dart:564:96 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion

warning - lib/src/engine/text_editing/text_editing.dart:567:91 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion

warning - lib/src/engine/text_editing/text_editing.dart:567:125 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion

Also it doesn't look like we're sending selectionAffinity information back to the framework (ref). Is this something that might cause issues in situations where baseOffset > extentOffset? Framework seems to just default to downstream (ref)

@knopp
Copy link
Member

knopp commented Aug 24, 2023

Thank you for this change @Renzo-Olivares!

There appear to be a few linting errors

warning - lib/src/engine/text_editing/text_editing.dart:564:96 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion

warning - lib/src/engine/text_editing/text_editing.dart:567:91 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion

warning - lib/src/engine/text_editing/text_editing.dart:567:125 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion

Also it doesn't look like we're sending selectionAffinity information back to the framework (ref). Is this something that might cause issues in situations where baseOffset > extentOffset? Framework seems to just default to downstream (ref)

TextAffinity should be reported, but it's somewhat orthogonal to inverted selection (baseOffset > extentOffset). I have a PR to properly report inverted selection here: #44806, it just waits for this one to land.

@Renzo-Olivares
Copy link
Contributor Author

@htoor3 Sorry about that must've missed these. They should be fixed now. selectionAffinity is important but piping it through has no affect on the fix in this PR.

In general the framework does use selectionAffinity to calculate some text boundaries (ref1) and (ref2) so it would be good to pipe it through eventually. From looking into the other platforms TextInputPlugin it seems only iOS/macOS have non-default values for selectionAffinity, for reference:
(Android)
(macOS)
(iOS)
(Windows)
(Linux)

@htoor3
Copy link
Contributor

htoor3 commented Aug 24, 2023

@htoor3 Sorry about that must've missed these. They should be fixed now. selectionAffinity is important but piping it through has no affect on the fix in this PR.

In general the framework does use selectionAffinity to calculate some text boundaries (ref1) and (ref2) so it would be good to pipe it through eventually. From looking into the other platforms TextInputPlugin it seems only iOS/macOS have non-default values for selectionAffinity, for reference: (Android) (macOS) (iOS) (Windows) (Linux)

Yep it didn't seem like it was a pressing TODO, but I was curious if it was related to this issue. I think there's a fallback in editable_text.dart (_checkNeedsAdjustAffinity()) that just overwrites the engine value with whatever the framework already has.

This change lgtm! There are just a few more breaking tests in what looks like Desktop Safari only - HybridTextEditing Supports new line at inverted selection and HybridTextEditing Supports deletion at inverted selection

Desktop Safari can be a little weird to test. Take a look at this comment here - it's possible adding these to ensure the placement of the input element could resolve those tests.

@Renzo-Olivares Renzo-Olivares force-pushed the delta-web-inverted-fix branch 2 times, most recently from 954d2f6 to 1a0ed36 Compare August 30, 2023 20:01
@knopp
Copy link
Member

knopp commented Aug 31, 2023

I can't reproduce the safari error locally (though I do get another test failing - "text editing styles invisible element"). Could this be a problem with different Safari version?

@knopp
Copy link
Member

knopp commented Aug 31, 2023

Right. It seems like the test that is failing for me (element.style.background is not transparent, but none) would pass in Safari 15, but fails in Safar 16.

@Renzo-Olivares
Copy link
Contributor Author

I don't think this PR is a result of those failures. I tried running tests locally on main without any changes and got two failures: HybridTextEditing focus and connection with blur and text editing styles invisible element. It looks like the linux web engine is failing so i'll try to build the engine on my linux machine and see if I can work this out.

@knopp
Copy link
Member

knopp commented Aug 31, 2023

I don't think this PR is a result of those failures. I tried running tests locally on main without any changes and got two failures: HybridTextEditing focus and connection with blur and text editing styles invisible element. It looks like the linux web engine is failing so i'll try to build the engine on my linux machine and see if I can work this out.

I think you're getting the failure because after setting style.background="transparent" on element and then getting the style.background returns none on Safari 16, but transparent on Safari 15. I think the CI might be running the tests on Safari 15, hence the discrepancy.

EDIT: messed up the version numbers.

@knopp
Copy link
Member

knopp commented Sep 3, 2023

I played with this a little bit. It turns out that Safari 15 doesn't support setting inputType on DOM input event.

var ev = new InputEvent('beforeinput', {'inputType' : 'deleteContentBackward'})
ev.inputType // always prints ""

InputEventInit.inputType has been only supported on Safari since this commit: WebKit/WebKit#3990. which didn't make it to Safari 15.

I don't know if it is reasonable to expect the CI to be updated to Safari 16 any time soon, but if not then these tests should maybe be disabled for Safari?

@Renzo-Olivares
Copy link
Contributor Author

@knopp Thank you for looking into that! Given that information I think its okay to disable these tests on Safari for the time being and a TODO explaining the issue. Our use of inputType here is not introduced by this PR this is just the first time we have tested this code path. Do you have any opinions on doing this @htoor3?

@htoor3
Copy link
Contributor

htoor3 commented Sep 7, 2023

@Renzo-Olivares I think that makes sense. Let me doublecheck with the team to determine what version of Safari is being used to run our CI tests and also what the version rolling process looks like.

Could you point me to the codepath where we're testing inputType?

@knopp
Copy link
Member

knopp commented Sep 7, 2023

@Renzo-Olivares I think that makes sense. Let me doublecheck with the team to determine what version of Safari is being used to run our CI tests and also what the version rolling process looks like.

Could you point me to the codepath where we're testing inputType?

Here we're creating a DomInputEvent with 'inputType': 'deleteContentBackward', which only works in Safari 16. In Safari 15 querying the inputType after creating the event always returns empty string.

@htoor3
Copy link
Contributor

htoor3 commented Sep 7, 2023

Thank you @knopp! Regarding the CI Safari version, it seems like it's tied to the CI server MacOS version and probably needs manual intervention to roll.

I think in that case, it's fair to disable them for Safari so we can get this fix in. I would add a TODO that links to a newly created issue outlining the Safari issue, mentioning to re-enable these after the Safari version rolls to 16 in CI.

@knopp
Copy link
Member

knopp commented Sep 8, 2023

Looks like the tests pass, can this be merged?

@Renzo-Olivares
Copy link
Contributor Author

Yes I'll merge it. I created an issue to re-enable the tests flutter/flutter#134271.

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 8, 2023
@auto-submit auto-submit bot merged commit 019715e into flutter:main Sep 8, 2023
25 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Sep 8, 2023
…134306)

flutter/engine@f09a139...6d6b448

2023-09-08 skia-flutter-autoroll@skia.org Roll Skia from 71e40cc0faf6 to c5e67d222f46 (4 revisions) (flutter/engine#45576)
2023-09-08 rmolivares@renzo-olivares.dev [Web] Fix insertions/deletions at inverted selection for TextEditingDeltas (flutter/engine#44693)
2023-09-08 skia-flutter-autoroll@skia.org Roll Skia from ece9f3a15b08 to 71e40cc0faf6 (1 revision) (flutter/engine#45575)

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
3 participants