File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ class ColoredTextEditingController extends TextEditingController {
3636 /// Reference to the focus of the LanguageTool TextField
3737 FocusNode ? focusNode;
3838
39+ /// Represents the scroll offset value of the LanguageTool TextField.
40+ double ? scrollOffset;
41+
3942 Object ? _fetchError;
4043
4144 /// An error that may have occurred during the API fetch.
@@ -367,10 +370,17 @@ class ColoredTextEditingController extends TextEditingController {
367370 textDirection: TextDirection .ltr,
368371 );
369372 final textFieldWidth = textFieldRenderBox? .size.width ?? 0 ;
373+ final scrollOffset = this .scrollOffset ?? 0 ;
374+
375+ double maxWidth = double .infinity;
376+ if (scrollOffset == 0 ) maxWidth = textFieldWidth;
377+
378+ textPainter.layout (minWidth: textFieldWidth, maxWidth: maxWidth);
370379
371- textPainter.layout (maxWidth: textFieldWidth);
380+ final adjustedOffset =
381+ Offset (localOffset.dx + scrollOffset, localOffset.dy);
372382
373- return textPainter.getPositionForOffset (localOffset ).offset;
383+ return textPainter.getPositionForOffset (adjustedOffset ).offset;
374384 }
375385
376386 /// The `onClosePopup` function is a callback method typically used
Original file line number Diff line number Diff line change @@ -43,13 +43,15 @@ class LanguageToolTextField extends StatefulWidget {
4343}
4444
4545class _LanguageToolTextFieldState extends State <LanguageToolTextField > {
46- final focusNode = FocusNode ();
46+ final _focusNode = FocusNode ();
47+ final _scrollController = ScrollController ();
4748
4849 @override
4950 void initState () {
5051 super .initState ();
51- widget.coloredController.focusNode = focusNode ;
52+ widget.coloredController.focusNode = _focusNode ;
5253 widget.coloredController.popupWidget = widget.mistakePopup;
54+ widget.coloredController.addListener (_textControllerListener);
5355 }
5456
5557 @override
@@ -79,7 +81,8 @@ class _LanguageToolTextFieldState extends State<LanguageToolTextField> {
7981 padding: const EdgeInsets .all (_padding),
8082 child: Center (
8183 child: TextField (
82- focusNode: focusNode,
84+ scrollController: _scrollController,
85+ focusNode: _focusNode,
8386 controller: widget.coloredController,
8487 style: widget.style,
8588 decoration: inputDecoration,
@@ -92,4 +95,14 @@ class _LanguageToolTextFieldState extends State<LanguageToolTextField> {
9295 },
9396 );
9497 }
98+
99+ void _textControllerListener () =>
100+ widget.coloredController.scrollOffset = _scrollController.offset;
101+
102+ @override
103+ void dispose () {
104+ _focusNode.dispose ();
105+ _scrollController.dispose ();
106+ super .dispose ();
107+ }
95108}
You can’t perform that action at this time.
0 commit comments