Update EditorState get renderEditor

pull/587/head
X Code 3 years ago
parent 430c6ae46e
commit aa9ce68605
  1. 2
      lib/src/widgets/delegate.dart
  2. 2
      lib/src/widgets/editor.dart
  3. 15
      lib/src/widgets/raw_editor.dart
  4. 9
      lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart
  5. 30
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart

@ -68,7 +68,7 @@ class EditorTextSelectionGestureDetectorBuilder {
/// provide a [EditorTextSelectionGestureDetector].
@protected
RenderEditor? getRenderEditor() {
return getEditor()!.getRenderEditor();
return getEditor()!.renderEditor;
}
/// Handler for [EditorTextSelectionGestureDetector.onTapDown].

@ -51,7 +51,7 @@ abstract class EditorState extends State<RawEditor>
implements TextSelectionDelegate {
ScrollController get scrollController;
RenderEditor getRenderEditor();
RenderEditor get renderEditor;
EditorTextSelectionOverlay? getSelectionOverlay();

@ -700,7 +700,7 @@ class RawEditorState extends EditorState
toolbarLayerLink: _toolbarLayerLink,
startHandleLayerLink: _startHandleLayerLink,
endHandleLayerLink: _endHandleLayerLink,
renderObject: getRenderEditor(),
renderObject: renderEditor,
selectionCtrls: widget.selectionCtrls,
selectionDelegate: this,
clipboardStatus: _clipboardStatus,
@ -753,7 +753,6 @@ class RawEditorState extends EditorState
return;
}
final renderEditor = getRenderEditor();
final viewport = RenderAbstractViewport.of(renderEditor);
final editorOffset =
renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport);
@ -776,10 +775,12 @@ class RawEditorState extends EditorState
});
}
/// The renderer for this widget's editor descendant.
///
/// This property is typically used to notify the renderer of input gestures.
@override
RenderEditor getRenderEditor() {
return _editorKey.currentContext?.findRenderObject() as RenderEditor;
}
RenderEditor get renderEditor =>
_editorKey.currentContext?.findRenderObject() as RenderEditor;
@override
void requestKeyboard() {
@ -806,7 +807,7 @@ class RawEditorState extends EditorState
@override
void debugAssertLayoutUpToDate() {
getRenderEditor().debugAssertLayoutUpToDate();
renderEditor.debugAssertLayoutUpToDate();
}
/// Shows the selection toolbar at the location of the current cursor.
@ -903,7 +904,7 @@ class RawEditorState extends EditorState
bool get readOnly => widget.readOnly;
@override
TextLayoutMetrics get textLayoutMetrics => getRenderEditor();
TextLayoutMetrics get textLayoutMetrics => renderEditor;
@override
AnimationController get floatingCursorResetController =>

@ -45,11 +45,11 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
@override
void bringIntoView(TextPosition position) {
final localRect = getRenderEditor().getLocalRectForCaret(position);
final localRect = renderEditor.getLocalRectForCaret(position);
final targetOffset = _getOffsetToRevealCaret(localRect, position);
scrollController.jumpTo(targetOffset.offset);
getRenderEditor().showOnScreen(rect: targetOffset.rect);
renderEditor.showOnScreen(rect: targetOffset.rect);
}
// Finds the closest scroll offset to the current scroll offset that fully
@ -66,7 +66,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
return RevealedOffset(offset: scrollController.offset, rect: rect);
}
final editableSize = getRenderEditor().size;
final editableSize = renderEditor.size;
final double additionalOffset;
final Offset unitOffset;
@ -76,8 +76,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
final expandedRect = Rect.fromCenter(
center: rect.center,
width: rect.width,
height: math.max(
rect.height, getRenderEditor().preferredLineHeight(position)),
height: math.max(rect.height, renderEditor.preferredLineHeight(position)),
);
additionalOffset = expandedRect.height >= editableSize.height

@ -187,7 +187,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
// origin, but the touch origin is used to determine which line the cursor is
// on, we need this offset to correctly render and move the cursor.
Offset _floatingCursorOffset(TextPosition textPosition) =>
Offset(0, getRenderEditor().preferredLineHeight(textPosition) / 2);
Offset(0, renderEditor.preferredLineHeight(textPosition) / 2);
@override
void updateFloatingCursor(RawFloatingCursorPoint point) {
@ -202,14 +202,14 @@ mixin RawEditorStateTextInputClientMixin on EditorState
_pointOffsetOrigin = point.offset;
final currentTextPosition =
TextPosition(offset: getRenderEditor().selection.baseOffset);
TextPosition(offset: renderEditor.selection.baseOffset);
_startCaretRect =
getRenderEditor().getLocalRectForCaret(currentTextPosition);
renderEditor.getLocalRectForCaret(currentTextPosition);
_lastBoundedOffset = _startCaretRect!.center -
_floatingCursorOffset(currentTextPosition);
_lastTextPosition = currentTextPosition;
getRenderEditor().setFloatingCursor(
renderEditor.setFloatingCursor(
point.state, _lastBoundedOffset!, _lastTextPosition!);
break;
case FloatingCursorDragState.Update:
@ -220,24 +220,22 @@ mixin RawEditorStateTextInputClientMixin on EditorState
_startCaretRect!.center + centeredPoint - floatingCursorOffset;
final preferredLineHeight =
getRenderEditor().preferredLineHeight(_lastTextPosition!);
_lastBoundedOffset =
getRenderEditor().calculateBoundedFloatingCursorOffset(
renderEditor.preferredLineHeight(_lastTextPosition!);
_lastBoundedOffset = renderEditor.calculateBoundedFloatingCursorOffset(
rawCursorOffset,
preferredLineHeight,
);
_lastTextPosition = getRenderEditor().getPositionForOffset(
getRenderEditor()
.localToGlobal(_lastBoundedOffset! + floatingCursorOffset));
getRenderEditor().setFloatingCursor(
_lastTextPosition = renderEditor.getPositionForOffset(renderEditor
.localToGlobal(_lastBoundedOffset! + floatingCursorOffset));
renderEditor.setFloatingCursor(
point.state, _lastBoundedOffset!, _lastTextPosition!);
final newSelection = TextSelection.collapsed(
offset: _lastTextPosition!.offset,
affinity: _lastTextPosition!.affinity);
// Setting selection as floating cursor moves will have scroll view
// bring background cursor into view
getRenderEditor()
.onSelectionChanged(newSelection, SelectionChangedCause.forcePress);
renderEditor.onSelectionChanged(
newSelection, SelectionChangedCause.forcePress);
break;
case FloatingCursorDragState.End:
// We skip animation if no update has happened.
@ -259,10 +257,10 @@ mixin RawEditorStateTextInputClientMixin on EditorState
/// and current position of background cursor)
void onFloatingCursorResetTick() {
final finalPosition =
getRenderEditor().getLocalRectForCaret(_lastTextPosition!).centerLeft -
renderEditor.getLocalRectForCaret(_lastTextPosition!).centerLeft -
_floatingCursorOffset(_lastTextPosition!);
if (floatingCursorResetController.isCompleted) {
getRenderEditor().setFloatingCursor(
renderEditor.setFloatingCursor(
FloatingCursorDragState.End, finalPosition, _lastTextPosition!);
_startCaretRect = null;
_lastTextPosition = null;
@ -275,7 +273,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
final lerpY =
lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!;
getRenderEditor().setFloatingCursor(FloatingCursorDragState.Update,
renderEditor.setFloatingCursor(FloatingCursorDragState.Update,
Offset(lerpX, lerpY), _lastTextPosition!,
resetLerpValue: lerpValue);
}

Loading…
Cancel
Save