Skip to content

Commit

Permalink
Fixed Scroll jumping up when typing past field height
Browse files Browse the repository at this point in the history
To replace my original PR memspace#315
I forked from the wrong fork, and wanted to simplify commits to one, and fix the Travis CL build failure it was reporting.
Issue discussed here memspace#171
  • Loading branch information
Skquark authored May 24, 2020
1 parent 4e2be31 commit 68221cb
Showing 1 changed file with 17 additions and 0 deletions.
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;
}
}
}

0 comments on commit 68221cb

Please sign in to comment.