Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class FleatherEditor extends StatefulWidget {
///
/// When set to `false` the editor always expands to fit the entire content
/// of the document and should normally be placed as a child of another
/// scrollable widget, otherwise the content may be clipped.
/// scrollable widget, otherwise the content may be clipped and an
/// error will be thrown if [enableInteractiveSelection] is `true`.
///
/// Set to `true` by default.
final bool scrollable;
Expand Down Expand Up @@ -1626,7 +1627,24 @@ class RawEditorState extends EditorState
bool _showCaretOnScreenScheduled = false;

void _showCaretOnScreen([bool withAnimation = true]) {
if (!widget.showCursor || _showCaretOnScreenScheduled) {
assert(
widget.enableInteractiveSelection
? _scrollController.positions.isNotEmpty
: true,
'ScrollController not attached to any scroll views. '
'When editor configured with scrollable = false and '
'enableInteractiveSelection = true, make sure the editor is the child '
'of a Scrollable widget.');
assert(
widget.showCursor ? _scrollController.positions.isNotEmpty : true,
'ScrollController not attached to any scroll views. '
'When editor configured with scrollable = false and '
'showCursor = true, make sure the editor is the child '
'of a Scrollable widget.');

if (!widget.showCursor ||
!widget.enableInteractiveSelection ||
_showCaretOnScreenScheduled) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ void main() {
// Scrollable forces expansion of editor
scrollable: false,
readOnly: true,
// We don't want to show cursor (will cause error if not scrollable)
// We don't want to enable selection interactions
// (will cause error if not scrollable)
enableSelectionInteraction: false,
// We don't want to show cursor
// (will cause error if not scrollable)
showCursor: false,
textWidthBasis: TextWidthBasis.longestLine,
);
Expand Down