From aa9ce6860527afca6517c68b5a625783515578b3 Mon Sep 17 00:00:00 2001 From: X Code Date: Wed, 5 Jan 2022 22:55:07 -0800 Subject: [PATCH] Update EditorState get renderEditor --- lib/src/widgets/delegate.dart | 2 +- lib/src/widgets/editor.dart | 2 +- lib/src/widgets/raw_editor.dart | 15 +++++----- ...editor_state_selection_delegate_mixin.dart | 9 +++--- ..._editor_state_text_input_client_mixin.dart | 30 +++++++++---------- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/lib/src/widgets/delegate.dart b/lib/src/widgets/delegate.dart index 6b80cd68..043229b4 100644 --- a/lib/src/widgets/delegate.dart +++ b/lib/src/widgets/delegate.dart @@ -68,7 +68,7 @@ class EditorTextSelectionGestureDetectorBuilder { /// provide a [EditorTextSelectionGestureDetector]. @protected RenderEditor? getRenderEditor() { - return getEditor()!.getRenderEditor(); + return getEditor()!.renderEditor; } /// Handler for [EditorTextSelectionGestureDetector.onTapDown]. diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 0b0eff9f..25e13748 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -51,7 +51,7 @@ abstract class EditorState extends State implements TextSelectionDelegate { ScrollController get scrollController; - RenderEditor getRenderEditor(); + RenderEditor get renderEditor; EditorTextSelectionOverlay? getSelectionOverlay(); diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index 8a646a4f..401ae176 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -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 => diff --git a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 5e8c13bb..055c9925 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -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 diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart index c845cedc..70dae3c0 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -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); }