From 6b662912c4f1c8ba6f8253547466df99cc505d2a Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Sat, 25 Jul 2026 06:55:23 -0400 Subject: [PATCH] fix: dispose owned scroll controllers and floating-cursor timer CodeScrollController allocated default ScrollControllers but dispose() only cleared the editor key, leaking two controllers per default editor. Track ownership and dispose only controllers we create. Also cancel _floatingCursorScrollTimer in _CodeInputController.dispose so disposing mid-edge-drag cannot leave a periodic timer on a detached controller. Signed-off-by: Sebastien Tardif --- lib/src/_code_input.dart | 4 ++++ lib/src/code_scroll.dart | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/src/_code_input.dart b/lib/src/_code_input.dart index 5b74002..97e561d 100644 --- a/lib/src/_code_input.dart +++ b/lib/src/_code_input.dart @@ -340,6 +340,10 @@ class _CodeInputController extends ChangeNotifier implements DeltaTextInputClien @override void dispose() { + if (_floatingCursorScrollTimer != null) { + _floatingCursorScrollTimer!.cancel(); + _floatingCursorScrollTimer = null; + } super.dispose(); _closeInputConnectionIfNeeded(); _controller.removeListener(_onCodeEditingChanged); diff --git a/lib/src/code_scroll.dart b/lib/src/code_scroll.dart index a8d15e7..63d2818 100644 --- a/lib/src/code_scroll.dart +++ b/lib/src/code_scroll.dart @@ -6,13 +6,17 @@ class CodeScrollController { final ScrollController verticalScroller; final ScrollController horizontalScroller; + final bool _ownsVerticalScroller; + final bool _ownsHorizontalScroller; GlobalKey? _editorKey; CodeScrollController({ ScrollController? verticalScroller, ScrollController? horizontalScroller, - }) : verticalScroller = verticalScroller ?? ScrollController(), + }) : _ownsVerticalScroller = verticalScroller == null, + _ownsHorizontalScroller = horizontalScroller == null, + verticalScroller = verticalScroller ?? ScrollController(), horizontalScroller = horizontalScroller ?? ScrollController(); void makeCenterIfInvisible(CodeLinePosition position) { @@ -31,6 +35,13 @@ class CodeScrollController { void dispose() { _editorKey = null; + // Only dispose controllers we allocated; caller-owned instances stay alive. + if (_ownsVerticalScroller) { + verticalScroller.dispose(); + } + if (_ownsHorizontalScroller) { + horizontalScroller.dispose(); + } } } \ No newline at end of file