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][iOS] Add tests for drag to select (Resolves #1613) #1627

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor][iOS] Add tests for drag to select. Resolves #1613

It was reported in #1610 that performing a horizontal drag isn't changing the selection. #1611 fixed the bug, but didn't include any tests.

This PR adds test for horizontal dragging inside a CustomScrollView. During the tests I got some failures because dragging can cause an upstream selection affinity. I added a custom Matcher to compare the selections, ignoring the affinity. We have something similar to this in NodePosition.isEquivalentTo.

Initially, these tests weren't failing, even without the fix. The reason is that dragSelectDocumentFromPositionByOffset always uses PointerDeviceKind.mouse as the device kind when starting the gesture. As this device kind isn't considered a drag device in mobile, the CustomScrollView didn't try to accept the gesture.

This PR adds a pointerDeviceKind parameter to dragSelectDocumentFromPositionByOffset, so we can override the device kind.

We should consider changing all dragXX methods to default the device kind depending on the platform

@@ -159,6 +159,7 @@ extension SuperEditorRobot on WidgetTester {
Future<void> dragSelectDocumentFromPositionByOffset({
required DocumentPosition from,
required Offset delta,
PointerDeviceKind pointerDeviceKind = PointerDeviceKind.mouse,
Copy link
Contributor

Choose a reason for hiding this comment

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

If this was added because all mobile tests need to drag with a finger instead of a mouse, then that means every mobile test will have to specify this. That seems fragile. Would it make more sense to make this nullable and then if it's null, the implementation chooses the most sensible device kind for the default platform?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

@@ -46,3 +47,74 @@ extension DragExtensions on WidgetTester {
return dragGesture;
}
}

/// Compares two selections, ignoring selection affinities.
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of what's here looks like it should exist in the package, not in test code. I assume that inspecting selection bounds is something that anyone might want to do.

Also, in this case, I don't think "selection equivalency" is appropriate, the way it was with node positions. Upstream vs downstream could truly result in different rendering, whereas the affinity for a single position shouldn't impact any visual behavior. I would approach this condition as one of equivalent bounds, or perhaps even equal bounds. But the point is that it's about the bounds, not the overall selection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of what's here looks like it should exist in the package, not in test code. I assume that inspecting selection bounds is something that anyone might want to do.

Are you suggesting that we add a method to the DocumentSelection class? I'm not sure we'll be using Matchers in the package code.

Also, in this case, I don't think "selection equivalency" is appropriate, the way it was with node positions. Upstream vs downstream could truly result in different rendering, whereas the affinity for a single position shouldn't impact any visual behavior.

My description wasn't accurate. I'm not ignoring the selection affinity itself, I'm ignoring the affinity of each NodePosition included in the selection.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we wouldn't add a Matcher to the source code. I was looking mostly at the code related to inspecting the selection. If this matcher still respects affinity of the selection, but ignores the affinity of the node positions, then that's a very specific differentiation. I wonder if that nuance might get lost and misunderstood over time.

Does this matcher need to care about selection affinity? Would it make sense to look only at the bounds, while ignoring all affinity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If this matcher still respects affinity of the selection, but ignores the affinity of the node positions, then that's a very specific differentiation.

This is what it does.

Does this matcher need to care about selection affinity? Would it make sense to look only at the bounds, while ignoring all affinity?

I think it should care about selection affinity. As it was mentioned, the selection affinity will impact the selection rendering.

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 matthew-carroll merged commit 6e97161 into superlistapp:main Dec 5, 2023
7 of 11 checks passed
angelosilvestre added a commit to angelosilvestre/super_editor that referenced this pull request Dec 5, 2023
@angelosilvestre angelosilvestre deleted the 1613_drag_tests branch December 5, 2023 21:45
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.

[SuperEditor][SuperReader][iOS] Add tests for selection gestures inside a CustomScrollView
2 participants