Skip to content

Commit a10e5cf

Browse files
committed
Parameterizing AutoScrollController in default editor
1 parent 695dfa9 commit a10e5cf

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

super_editor/lib/src/default_editor/super_editor.dart

+15-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import 'package:super_editor/src/default_editor/list_items.dart';
2222
import 'package:super_editor/src/default_editor/tasks.dart';
2323
import 'package:super_editor/src/infrastructure/_logging.dart';
2424
import 'package:super_editor/src/infrastructure/content_layers.dart';
25-
import 'package:super_editor/src/infrastructure/document_gestures.dart';
2625
import 'package:super_editor/src/infrastructure/documents/document_scaffold.dart';
2726
import 'package:super_editor/src/infrastructure/documents/document_scroller.dart';
2827
import 'package:super_editor/src/infrastructure/documents/selection_leader_document_layer.dart';
@@ -132,7 +131,7 @@ class SuperEditor extends StatefulWidget {
132131
this.iOSToolbarBuilder,
133132
this.createOverlayControlsClipper,
134133
this.plugins = const {},
135-
this.scrollOff = AxisOffset.zero,
134+
this.autoScrollController,
136135
this.debugPaint = const DebugPaintConfig(),
137136
this.documentLayoutBuilder,
138137
}) : stylesheet = stylesheet ?? defaultStylesheet,
@@ -142,10 +141,6 @@ class SuperEditor extends StatefulWidget {
142141
: [...defaultComponentBuilders, const UnknownComponentBuilder()],
143142
super(key: key);
144143

145-
/// How far the selection extent can be from the top and bottom before triggering auto-scroll behavior. Defaults to
146-
/// zero for both top and bottom, so scrolling will only take place if the caret would leave the viewport.
147-
final AxisOffset scrollOff;
148-
149144
/// [FocusNode] for the entire `SuperEditor`.
150145
final FocusNode? focusNode;
151146

@@ -169,6 +164,8 @@ class SuperEditor extends StatefulWidget {
169164
/// `Scrollable`.
170165
final ScrollController? scrollController;
171166

167+
final AutoScrollController? autoScrollController;
168+
172169
/// [GlobalKey] that's bound to the [DocumentLayout] within
173170
/// this `SuperEditor`.
174171
///
@@ -398,9 +395,7 @@ class SuperEditorState extends State<SuperEditor> {
398395
_composer = widget.composer;
399396

400397
_scrollController = widget.scrollController ?? ScrollController();
401-
_autoScrollController = AutoScrollController(
402-
selectionExtentAutoScrollBoundary: widget.scrollOff,
403-
);
398+
_autoScrollController = widget.autoScrollController ?? AutoScrollController();
404399

405400
_docLayoutKey = widget.documentLayoutKey ?? GlobalKey();
406401

@@ -461,6 +456,13 @@ class SuperEditorState extends State<SuperEditor> {
461456
_scrollController = widget.scrollController ?? ScrollController();
462457
}
463458

459+
if (widget.autoScrollController != oldWidget.autoScrollController) {
460+
if (oldWidget.autoScrollController == null) {
461+
_autoScrollController.dispose();
462+
}
463+
_autoScrollController = widget.autoScrollController ?? AutoScrollController();
464+
}
465+
464466
_recomputeIfLayoutShouldShowCaret();
465467
}
466468

@@ -479,6 +481,10 @@ class SuperEditorState extends State<SuperEditor> {
479481
_focusNode.dispose();
480482
}
481483

484+
if (widget.autoScrollController == null) {
485+
_autoScrollController.dispose();
486+
}
487+
482488
super.dispose();
483489
}
484490

super_editor/lib/super_editor.dart

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export 'src/default_editor/text_tokenizing/pattern_tags.dart';
5050
export 'src/default_editor/text_tokenizing/tags.dart';
5151
export 'src/default_editor/text_tokenizing/stable_tags.dart';
5252
export 'src/default_editor/unknown_component.dart';
53+
export 'src/default_editor/document_scrollable.dart';
5354

5455
// Document operations used by SuperEditor and/or SuperReader,
5556
// also made available for public use.

0 commit comments

Comments
 (0)