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

[SuperTextField][Android] Fix drag handle jumping when adding text at the end (Resolves #1114) #1124

Merged

Conversation

angelosilvestre
Copy link
Collaborator

[SuperTextField][Android] Fix drag handle jumping when adding text at the end. Resolves #1114

When the text field is center-aligned, typing at the end of the text field causes the drag handle to "flash" at the center of the text field before being displayed at the correct position:

2023-05-09.19-56-12.mp4

The cause seems to be a timing issue. We are computing the drag handle offset during build and it seems we are requesting the caret offset while the text layout isn't updated with the new text.

This PR changes the AndroidEditingOverlayControls to compute and cache the caret offset in a post-frame callback after the text/selection changes.

After the changes:

2023-05-09.20-00-09.mp4

Unfortunately, I couldn't write a test for it. We don't seem to have the same timing issues in the widget tests.

bool get _shouldShowCollapsedHandle =>
widget.editingController.textController.selection.isCollapsed && !_isDraggingBase && !_isDraggingExtent;

/// Holds the offset in text layout space where the collapsed drag handle is displayed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test to see if any similar positioning issues occur with expanded handles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't notice issues like this with expanded handles.

/// Update the offset for the collapsed handle and call `setState`.
///
/// Re-schedules the update if we can't compute compute the offset at the current frame.
void _updateOffsetForCollapsedHandleAndRebuild() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks nearly identical to the other method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is nearly identical. The only difference is that one method directly assignes the value because it is called in the build phase and the other calls setState.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we should de-duplicate it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After reviewing and testing again, it seems we don't need two methods. We aren't calling this from the build phase.
Updated.

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 5227a93 into superlistapp:main Jul 25, 2023
7 of 8 checks passed
angelosilvestre added a commit to angelosilvestre/super_editor that referenced this pull request Jul 25, 2023
@angelosilvestre angelosilvestre deleted the 1114_drag_handle_jumping branch July 25, 2023 23:18
matthew-carroll pushed a commit that referenced this pull request Jul 25, 2023
quaaantumdev pushed a commit to quaaantumdev/super_editor that referenced this pull request Aug 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.

[SuperTextField][Android] - Cursor Jumps
2 participants