Skip to content

fix: guard delayed drag autoscroll after dispose#118

Open
SebTardif wants to merge 1 commit into
reqable:mainfrom
SebTardif:fix/drag-autoscroll-dispose
Open

fix: guard delayed drag autoscroll after dispose#118
SebTardif wants to merge 1 commit into
reqable:mainfrom
SebTardif:fix/drag-autoscroll-dispose

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary

Delayed drag autoscroll callbacks can run after the CodeEditor is disposed. They call render / ensureRender, which cast findRenderObject() with as _CodeFieldRender. When currentContext is null after dispose, that cast throws and crashes the app.

This change:

  • Returns early when !mounted in the gesture detector autoscroll loop
  • Uses a safe is! _CodeFieldRender check instead of a force cast before calling autoScrollWhenDragging (desktop drag + mobile handle drag paths)

Failure scenario

  1. User starts a text selection drag (or drags a mobile selection handle).
  2. Autoscroll schedules Future.delayed(100ms, ...).
  3. The editor is removed from the tree before the callback runs.
  4. The callback dereferences a null render object via as _CodeFieldRender and crashes.

Bug origin

_autoScrollWhenDragging has used Future.delayed since the selection gesture code was introduced (MegatronKing, 2024-02). The mobile handle paths use the same pattern with ensureRender.

Related

Test plan

  • Diff limited to the three delayed autoscroll callbacks
  • Manual: start drag selection, dispose the editor mid-drag, confirm no crash
  • CI analysis on the package

No automated widget test added: this path depends on Flutter render objects and delayed callbacks; the fix is the same null-safe pattern already used elsewhere in _MobileSelectionOverlayController for optional render lookups.

Future.delayed callbacks in selection drag autoscroll can fire after
the editor is removed. The non-null cast on findRenderObject then
crashes. Check mounted and use a safe typed cast before scrolling.
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.

1 participant