Fix for errors when selecting text in a non-scrollable editor

pull/620/head
Nicolas Dion Bouchard 3 years ago
parent a3f26f3c14
commit d51139d3a6
  1. 23
      lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart

@ -63,7 +63,9 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
final localRect = renderEditor.getLocalRectForCaret(position); final localRect = renderEditor.getLocalRectForCaret(position);
final targetOffset = _getOffsetToRevealCaret(localRect, position); final targetOffset = _getOffsetToRevealCaret(localRect, position);
scrollController.jumpTo(targetOffset.offset); if (scrollController.hasClients) {
scrollController.jumpTo(targetOffset.offset);
}
renderEditor.showOnScreen(rect: targetOffset.rect); renderEditor.showOnScreen(rect: targetOffset.rect);
} }
@ -77,7 +79,9 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
// `renderEditable.preferredLineHeight`, before the target scroll offset is // `renderEditable.preferredLineHeight`, before the target scroll offset is
// calculated. // calculated.
RevealedOffset _getOffsetToRevealCaret(Rect rect, TextPosition position) { RevealedOffset _getOffsetToRevealCaret(Rect rect, TextPosition position) {
if (!scrollController.position.allowImplicitScrolling) { // Make sure scrollController is attached
if (scrollController.hasClients &&
!scrollController.position.allowImplicitScrolling) {
return RevealedOffset(offset: scrollController.offset, rect: rect); return RevealedOffset(offset: scrollController.offset, rect: rect);
} }
@ -102,12 +106,17 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
// No overscrolling when encountering tall fonts/scripts that extend past // No overscrolling when encountering tall fonts/scripts that extend past
// the ascent. // the ascent.
final targetOffset = (additionalOffset + scrollController.offset).clamp( var targetOffset = additionalOffset;
scrollController.position.minScrollExtent, if (scrollController.hasClients) {
scrollController.position.maxScrollExtent, targetOffset = (additionalOffset + scrollController.offset).clamp(
); scrollController.position.minScrollExtent,
scrollController.position.maxScrollExtent,
);
}
final offsetDelta = scrollController.offset - targetOffset; final offsetDelta =
(scrollController.hasClients ? scrollController.offset : 0) -
targetOffset;
return RevealedOffset( return RevealedOffset(
rect: rect.shift(unitOffset * offsetDelta), offset: targetOffset); rect: rect.shift(unitOffset * offsetDelta), offset: targetOffset);
} }

Loading…
Cancel
Save