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][SuperReader] - Lock scrolling when content fits within available space (Resolves #1409) #1421

Merged
merged 13 commits into from
Sep 30, 2023

Conversation

rutvik110
Copy link
Collaborator

@rutvik110 rutvik110 commented Sep 9, 2023

[SuperEditor][SuperReader] - Lock scrolling when content fits within available space (Resolves #1409)

Currently in the SuperEditor or SuperReader, the document is scrollable even if the content fits within the available space as seen in the below demo.

This demo wraps the SuperEditor within an IntrinsicHeight widget to demonstrate the issue,

Screen.Recording.2023-09-07.at.1.02.09.PM.mov

This PR tries to address this issue by locking the scrolling for the document in such cases. We lock the scrolling when the content of the document fits within the available viewport space and there isn't any unconsumed content within the Scrollable.

Scroll lock is introduced within both DocumentScroller and AutoScrollController. When the scroll lock is enabled, any calls/actions related to scrolling are ignored to prevent the document from scrolling.

After this latest updates, the scrolling is locked whenever content fits within available space as seen in the following demo,

f_scroll_lock.mp4

@rutvik110
Copy link
Collaborator Author

rutvik110 commented Sep 9, 2023

@matthew-carroll Could you please take a look at the approach I took to fix this issue? It's still WIP but wanted your opinion on the approach and see if whether this is the direction that we want to move in with this issue.

@matthew-carroll
Copy link
Contributor

@rutvik110 before evaluating your choice of solution, can you describe what you investigated? For example, why is the scrollable letting us scroll when there's no content to scroll?

@rutvik110
Copy link
Collaborator Author

@rutvik110 before evaluating your choice of solution, can you describe what you investigated? For example, why is the scrollable letting us scroll when there's no content to scroll?

There seems to be two reasons here that are causing the overscroll.

The first reason is related to our handling of the scrolling within Scrollable. In case of auto-scrolling in response to mouse events, currently we are always trying to scroll irrespective of whether there's any content left to scroll.
This calls to scroll is leading to the overscroll/scroll-bounce that we are noticing in demo you shared.

Second reason is bit more ambiguous and it may be totally different issue that I may've confused with this one but here it's. It seems to be particularly related to usage of IntrinisicHeight. I noticed that when we have large chunks of paragraphs within SuperEditor, the final height calculated by the IntrinisicHeight to layout the SuperEditor isn't correct and is smaller by some magnitude. So the SuperEditor is laid out with the height smaller than it's contents actual height which results in introducing some content within SuperEditor beyond its scrollable viewport.

Screen.Recording.2023-09-12.at.8.45.55.AM.mov

@@ -387,6 +387,12 @@ class AutoScrollController with ChangeNotifier {
return;
}

// There's no content to scroll. So, we can't go ballistic as it would result
Copy link
Collaborator Author

@rutvik110 rutvik110 Sep 12, 2023

Choose a reason for hiding this comment

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

@matthew-carroll I've reverted the previous additions I made to this issue. I think those additions were targeting a different issue than the one we're trying to solve here.

Wrt the first reason I mentioned above for overscrolling, this update resolves that.
Currently, we do a final scroll call with goBallistic to animate to a new scroll position at the end of the mouse events(specifically pan events) that results in scrolling the content.
I added a check to prevent making this call if there's no content to scroll to or maxScrollExtent is 0.

This should take care of the overscroll that was happening when the content fits within the available space.

@@ -50,7 +50,8 @@ class _SwitchDocumentDemoState extends State<SwitchDocumentDemo> {
child: Column(
children: [
_buildDocSelector(),
Expanded(
IntrinsicHeight(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this.

@rutvik110
Copy link
Collaborator Author

Also, what about when the user is using the scroll wheel? I was able to overscroll using the scroll wheel which I believe is unrelated to going ballistic.

ah yah, had to add the same max extent check to jumpBy which resolved this. @matthew-carroll Could you please re-check this on your end?

Also, what are your thoughts on the previous comment I made regarding extent check in the reverse direction?

@matthew-carroll
Copy link
Contributor

I think the current changes are probably good as-is. Can you confirm that these changes work for SuperReader as well as SuperEditor? Also, can you write a test for each of these scenarios in the appropriate test file?

And please don't forget to revert the code that I mentioned in an earlier comment.

@rutvik110
Copy link
Collaborator Author

Great! Will check on SuperReader once which I believe should work fine as well and get onto writing tests for this.

@rutvik110 rutvik110 force-pushed the 1409_content_fit_scroll_lock branch from 7e9353d to cf930f8 Compare September 23, 2023 09:53

group("doesn't scroll editor when content fits within the available space", () {
testWidgetsOnDesktop(
"attempts to scroll editor vertically in both directions using trackpad",
Copy link
Contributor

Choose a reason for hiding this comment

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

These test names aren't great. Look at what the final test name is:

"doesn't scroll editor when content fits within the available space attempts to scroll editor vertically in both directions using trackpad"

I think you can describe the group and test in a way that's much more concise, and makes sense when read as the final test description.

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 a49960f into main Sep 30, 2023
10 of 11 checks passed
@matthew-carroll matthew-carroll deleted the 1409_content_fit_scroll_lock branch September 30, 2023 18:09
rutvik110 added a commit that referenced this pull request Oct 2, 2023
matthew-carroll pushed a commit that referenced this pull request Oct 2, 2023
raulmabe-labhouse pushed a commit to LabhouseMobile/super_editor that referenced this pull request Oct 10, 2023
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] - Is scrollable when it doesn't need to be
2 participants