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

[SuperEditor][Mobile] Fix downstream image caret position (Resolves #1959) #1967

Merged
merged 7 commits into from May 13, 2024

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor][Mobile] Fix downstream image caret position. Resolves #1959

Tapping close to the trailing edge of an image places the selection correctly, but the caret isn't displayed. We had the same issue in the past on desktop. It was fixed by #1820, but mobile doesn't use the same caret layer that desktop uses, so the issue is still present on mobile.

The root cause is the same of the desktop issue:

The downstream caret is positioned at (right, 0), so when the image takes all the available screen width (like in the demo app), the caret is positioned off-screen. Block level elements that have padding don't have this issue, because there is room to render the caret.

The same solution was applied:

This PR changes the caret overlay to check whether the caret rect is placed outside of its bounds at the right side. If it is, the caret position is adjusted.

The golden tests for Android are still failing due to this exception:

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
'package:flutter_test/src/_matchers_io.dart': Failed assertion: line 29 pos 10:
'!renderObject.debugNeedsPaint': is not true.

When the exception was thrown, this was the stack:
#2      captureImage (package:flutter_test/src/_matchers_io.dart:29:10)
#3      MatchesGoldenFile.matchAsync (package:flutter_test/src/_matchers_io.dart:96:21)
#4      _expect (package:matcher/src/expect/expect.dart:109:26)
#5      expectLater (package:matcher/src/expect/expect.dart:73:5)
#6      expectLater (package:flutter_test/src/widget_tester.dart:511:25)
#7      compareWithGolden (package:golden_toolkit/src/testing_tools.dart:296:9)

It seems to be caused by the Follower used by the Android collapsed handle.

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll Can you do a first pass review?

I still don't know what to do with this assertion failure, but it should impact the fix.

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll We had the golden test issue on the past on linux and worked around that with the following code:

 @override
  void markNeedsPaint() {
    super.markNeedsPaint();

    if (kDebugMode &&
        !kIsWeb &&
        Platform.isLinux &&
        Platform.environment.containsKey('FLUTTER_TEST') &&
        !WidgetsBinding.instance.hasScheduledFrame) {
      // We are running on a linux test and we don't have a scheduled frame.
      //
      // We ran into an issue in some golden tests, on linux only, where `debugNeedsPaint`
      // is `true` after the build/layout/phase pipeline. This causes the tests to fail,
      // because trying to capture the image of a `RenderObject` throws an assertion failure
      // if `debugNeedsPaint` is `true`. To avoid that, immediately schedule a new frame,
      // so Flutter pipeline runs again before we try to capture the image.
      WidgetsBinding.instance.scheduleFrame();
    }
  }

Should we also check for Android?

@matthew-carroll
Copy link
Contributor

@angelosilvestre I think we mentioned it on our call, but you can go ahead and let that particular check run for all platforms.

@matthew-carroll
Copy link
Contributor

CC @BazinC

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll I'm getting a failure on the new goldens on CI only that seems related to some antialiasing on the drag handle.

Test image:

super-editor-image-caret-upstream-android_testImage

Master image:

super-editor-image-caret-upstream-android_masterImage

Isolate diff:

super-editor-image-caret-upstream-android_isolatedDiff

Any ideas?

@matthew-carroll
Copy link
Contributor

@angelosilvestre can you just regenerate that golden?

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll Locally, the regenerated golden is identical to the previous one...

@matthew-carroll
Copy link
Contributor

@angelosilvestre if your local Flutter version is identical to the CI Flutter version, then I'm not sure why we're seeing different results. If that's truly the case, then consider using the tooling that we created, which allows a certain number of pixels to be different before failing the test.

@angelosilvestre
Copy link
Collaborator Author

After using our tooling that tolerates small differences, I got back to the infamous debugNeedsPaint assertion failure.

@matthew-carroll
Copy link
Contributor

@angelosilvestre are the goldens the only remaining problem? If so, let's file an issue to look into it and get this fix merged.

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll Yes, the only problem is the failing goldens on Android. I modified these tests to be skipped so we can try to find out the reason.

Copy link
Contributor

@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

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

LGTM

@matthew-carroll
Copy link
Contributor

@angelosilvestre please be sure to file an issue, if you haven't already

@matthew-carroll matthew-carroll merged commit 5481c4e into main May 13, 2024
11 checks passed
@matthew-carroll matthew-carroll deleted the 1959_mobile_image_caret branch May 13, 2024 22:14
matthew-carroll pushed a commit that referenced this pull request May 15, 2024
Resolves #1959) (#1995)

[SuperEditor][Mobile] Fix downstream image caret position (Resolves #1959) (#1967)

Co-authored-by: Angelo Silvestre <angelosilvestre.ccp@gmail.com>
quaaantumdev pushed a commit to quaaantumdev/super_editor that referenced this pull request May 16, 2024
Resolves superlistapp#1959) (superlistapp#1995)

[SuperEditor][Mobile] Fix downstream image caret position (Resolves superlistapp#1959) (superlistapp#1967)

Co-authored-by: Angelo Silvestre <angelosilvestre.ccp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mobile: Caret position is wrong when dealing with ImageNode
2 participants