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][Android] Fix scrolling when dragging at empty space (Resolves #2001) #2037

Merged
merged 1 commit into from
May 25, 2024

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor][Android] Fix scrolling when dragging at empty space. Resolves #2001

When the user drags starting from an empty space, for example, the area of the document padding, the following crash happens and the editor does not scroll:

════════ Exception caught by gesture ═══════════════════════════════════════════
The following _TypeError was thrown while handling a gesture:
Null check operator used on a null value

When the exception was thrown, this was the stack:
#0      _AndroidDocumentTouchInteractorState._onPanStart (package:super_editor/src/default_editor/document_gestures_touch_android.dart:997:100)
document_gestures_touch_android.dart:997
#1      DragGestureRecognizer._checkStart.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:785:53)
monodrag.dart:785
#2      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:344:24)
recognizer.dart:344
#3      DragGestureRecognizer._checkStart (package:flutter/src/gestures/monodrag.dart:785:7)
monodrag.dart:785
#4      DragGestureRecognizer._checkDrag (package:flutter/src/gestures/monodrag.dart:752:5)
monodrag.dart:752
#5      DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:679:7)
monodrag.dart:679
#6      GestureArenaManager._resolveInFavorOf (package:flutter/src/gestures/arena.dart:282:12)
arena.dart:282
#7      GestureArenaManager._resolve (package:flutter/src/gestures/arena.dart:233:11)
arena.dart:233

The root cause is that, when we check if the user tapped over the caret, we assume that the tap down position can always be mapped to a DocumentPosition, which isn't the case. This only happens if the editor has a collapsed selection.

This PR fixes the issue and adds test for scenarios with collapsed selection, expanded selection and no selection.

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 e698f2f into main May 25, 2024
11 checks passed
@matthew-carroll matthew-carroll deleted the 2001_android-dragging-empty-space branch May 25, 2024 23:33
quaaantumdev pushed a commit to quaaantumdev/super_editor that referenced this pull request Jun 1, 2024
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.

Android interactor assumes an offset will map to a document position
2 participants