Skip to content
Open
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
17 changes: 17 additions & 0 deletions packages/zefyr/lib/src/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'package:notus/notus.dart';

import 'code.dart';
Expand Down Expand Up @@ -172,6 +173,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
super.initState();
_focusAttachment = _focusNode.attach(context);
_input = InputConnectionController(_handleRemoteValueChange);
_scrollController.addListener(_handleScrollChange);
_updateSubscriptions();
}

Expand Down Expand Up @@ -223,6 +225,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
//

final ScrollController _scrollController = ScrollController();
double _scrollOffset = 0.0;
ZefyrRenderContext _renderContext;
CursorTimer _cursorTimer;
InputConnectionController _input;
Expand Down Expand Up @@ -284,6 +287,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
_renderContext.removeListener(_handleRenderContextChange);
widget.controller.removeListener(_handleLocalValueChange);
_focusNode.removeListener(_handleFocusChange);
_scrollController.removeListener(_handleScrollChange);
_input.closeConnection();
_cursorTimer.stop();
}
Expand Down Expand Up @@ -320,4 +324,17 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
// nothing to update internally.
});
}

void _handleScrollChange() {
ScrollDirection scrollDirection = _scrollController.position.userScrollDirection;
if (scrollDirection == ScrollDirection.idle && widget.controller.selection.isCollapsed) {
if (widget.controller.document.length - 1 == widget.controller.selection.end) {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
} else {
_scrollController.jumpTo(_scrollOffset);
}
} else {
_scrollOffset = _scrollController.offset;
}
}
}