Skip to content

Commit 38c5afc

Browse files
committed
Parameterizing AutoScrollController in default editor
1 parent 7438fc4 commit 38c5afc

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
@@ -21,7 +21,6 @@ import 'package:super_editor/src/default_editor/list_items.dart';
2121
import 'package:super_editor/src/default_editor/tasks.dart';
2222
import 'package:super_editor/src/infrastructure/_logging.dart';
2323
import 'package:super_editor/src/infrastructure/content_layers.dart';
24-
import 'package:super_editor/src/infrastructure/document_gestures.dart';
2524
import 'package:super_editor/src/infrastructure/documents/document_scaffold.dart';
2625
import 'package:super_editor/src/infrastructure/documents/document_scroller.dart';
2726
import 'package:super_editor/src/infrastructure/documents/selection_leader_document_layer.dart';
@@ -131,7 +130,7 @@ class SuperEditor extends StatefulWidget {
131130
this.iOSToolbarBuilder,
132131
this.createOverlayControlsClipper,
133132
this.plugins = const {},
134-
this.scrollOff = AxisOffset.zero,
133+
this.autoScrollController,
135134
this.debugPaint = const DebugPaintConfig(),
136135
this.documentLayoutBuilder,
137136
}) : stylesheet = stylesheet ?? defaultStylesheet,
@@ -141,10 +140,6 @@ class SuperEditor extends StatefulWidget {
141140
: [...defaultComponentBuilders, const UnknownComponentBuilder()],
142141
super(key: key);
143142

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

@@ -168,6 +163,8 @@ class SuperEditor extends StatefulWidget {
168163
/// `Scrollable`.
169164
final ScrollController? scrollController;
170165

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

399396
_scrollController = widget.scrollController ?? ScrollController();
400-
_autoScrollController = AutoScrollController(
401-
selectionExtentAutoScrollBoundary: widget.scrollOff,
402-
);
397+
_autoScrollController = widget.autoScrollController ?? AutoScrollController();
403398

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

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

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

@@ -478,6 +480,10 @@ class SuperEditorState extends State<SuperEditor> {
478480
_focusNode.dispose();
479481
}
480482

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

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)