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]. /// provide a [EditorTextSelectionGestureDetector].
@protected @protected
RenderEditor? getRenderEditor() { RenderEditor? getRenderEditor() {
return getEditor()!.getRenderEditor(); return getEditor()!.renderEditor;
} }
/// Handler for [EditorTextSelectionGestureDetector.onTapDown]. /// Handler for [EditorTextSelectionGestureDetector.onTapDown].

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

@ -700,7 +700,7 @@ class RawEditorState extends EditorState
toolbarLayerLink: _toolbarLayerLink, toolbarLayerLink: _toolbarLayerLink,
startHandleLayerLink: _startHandleLayerLink, startHandleLayerLink: _startHandleLayerLink,
endHandleLayerLink: _endHandleLayerLink, endHandleLayerLink: _endHandleLayerLink,
renderObject: getRenderEditor(), renderObject: renderEditor,
selectionCtrls: widget.selectionCtrls, selectionCtrls: widget.selectionCtrls,
selectionDelegate: this, selectionDelegate: this,
clipboardStatus: _clipboardStatus, clipboardStatus: _clipboardStatus,
@ -753,7 +753,6 @@ class RawEditorState extends EditorState
return; return;
} }
final renderEditor = getRenderEditor();
final viewport = RenderAbstractViewport.of(renderEditor); final viewport = RenderAbstractViewport.of(renderEditor);
final editorOffset = final editorOffset =
renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport); 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 @override
RenderEditor getRenderEditor() { RenderEditor get renderEditor =>
return _editorKey.currentContext?.findRenderObject() as RenderEditor; _editorKey.currentContext?.findRenderObject() as RenderEditor;
}
@override @override
void requestKeyboard() { void requestKeyboard() {
@ -806,7 +807,7 @@ class RawEditorState extends EditorState
@override @override
void debugAssertLayoutUpToDate() { void debugAssertLayoutUpToDate() {
getRenderEditor().debugAssertLayoutUpToDate(); renderEditor.debugAssertLayoutUpToDate();
} }
/// Shows the selection toolbar at the location of the current cursor. /// Shows the selection toolbar at the location of the current cursor.
@ -903,7 +904,7 @@ class RawEditorState extends EditorState
bool get readOnly => widget.readOnly; bool get readOnly => widget.readOnly;
@override @override
TextLayoutMetrics get textLayoutMetrics => getRenderEditor(); TextLayoutMetrics get textLayoutMetrics => renderEditor;
@override @override
AnimationController get floatingCursorResetController => AnimationController get floatingCursorResetController =>

@ -45,11 +45,11 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
@override @override
void bringIntoView(TextPosition position) { void bringIntoView(TextPosition position) {
final localRect = getRenderEditor().getLocalRectForCaret(position); final localRect = renderEditor.getLocalRectForCaret(position);
final targetOffset = _getOffsetToRevealCaret(localRect, position); final targetOffset = _getOffsetToRevealCaret(localRect, position);
scrollController.jumpTo(targetOffset.offset); 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 // 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); return RevealedOffset(offset: scrollController.offset, rect: rect);
} }
final editableSize = getRenderEditor().size; final editableSize = renderEditor.size;
final double additionalOffset; final double additionalOffset;
final Offset unitOffset; final Offset unitOffset;
@ -76,8 +76,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
final expandedRect = Rect.fromCenter( final expandedRect = Rect.fromCenter(
center: rect.center, center: rect.center,
width: rect.width, width: rect.width,
height: math.max( height: math.max(rect.height, renderEditor.preferredLineHeight(position)),
rect.height, getRenderEditor().preferredLineHeight(position)),
); );
additionalOffset = expandedRect.height >= editableSize.height 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 // 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. // on, we need this offset to correctly render and move the cursor.
Offset _floatingCursorOffset(TextPosition textPosition) => Offset _floatingCursorOffset(TextPosition textPosition) =>
Offset(0, getRenderEditor().preferredLineHeight(textPosition) / 2); Offset(0, renderEditor.preferredLineHeight(textPosition) / 2);
@override @override
void updateFloatingCursor(RawFloatingCursorPoint point) { void updateFloatingCursor(RawFloatingCursorPoint point) {
@ -202,14 +202,14 @@ mixin RawEditorStateTextInputClientMixin on EditorState
_pointOffsetOrigin = point.offset; _pointOffsetOrigin = point.offset;
final currentTextPosition = final currentTextPosition =
TextPosition(offset: getRenderEditor().selection.baseOffset); TextPosition(offset: renderEditor.selection.baseOffset);
_startCaretRect = _startCaretRect =
getRenderEditor().getLocalRectForCaret(currentTextPosition); renderEditor.getLocalRectForCaret(currentTextPosition);
_lastBoundedOffset = _startCaretRect!.center - _lastBoundedOffset = _startCaretRect!.center -
_floatingCursorOffset(currentTextPosition); _floatingCursorOffset(currentTextPosition);
_lastTextPosition = currentTextPosition; _lastTextPosition = currentTextPosition;
getRenderEditor().setFloatingCursor( renderEditor.setFloatingCursor(
point.state, _lastBoundedOffset!, _lastTextPosition!); point.state, _lastBoundedOffset!, _lastTextPosition!);
break; break;
case FloatingCursorDragState.Update: case FloatingCursorDragState.Update:
@ -220,24 +220,22 @@ mixin RawEditorStateTextInputClientMixin on EditorState
_startCaretRect!.center + centeredPoint - floatingCursorOffset; _startCaretRect!.center + centeredPoint - floatingCursorOffset;
final preferredLineHeight = final preferredLineHeight =
getRenderEditor().preferredLineHeight(_lastTextPosition!); renderEditor.preferredLineHeight(_lastTextPosition!);
_lastBoundedOffset = _lastBoundedOffset = renderEditor.calculateBoundedFloatingCursorOffset(
getRenderEditor().calculateBoundedFloatingCursorOffset(
rawCursorOffset, rawCursorOffset,
preferredLineHeight, preferredLineHeight,
); );
_lastTextPosition = getRenderEditor().getPositionForOffset( _lastTextPosition = renderEditor.getPositionForOffset(renderEditor
getRenderEditor() .localToGlobal(_lastBoundedOffset! + floatingCursorOffset));
.localToGlobal(_lastBoundedOffset! + floatingCursorOffset)); renderEditor.setFloatingCursor(
getRenderEditor().setFloatingCursor(
point.state, _lastBoundedOffset!, _lastTextPosition!); point.state, _lastBoundedOffset!, _lastTextPosition!);
final newSelection = TextSelection.collapsed( final newSelection = TextSelection.collapsed(
offset: _lastTextPosition!.offset, offset: _lastTextPosition!.offset,
affinity: _lastTextPosition!.affinity); affinity: _lastTextPosition!.affinity);
// Setting selection as floating cursor moves will have scroll view // Setting selection as floating cursor moves will have scroll view
// bring background cursor into view // bring background cursor into view
getRenderEditor() renderEditor.onSelectionChanged(
.onSelectionChanged(newSelection, SelectionChangedCause.forcePress); newSelection, SelectionChangedCause.forcePress);
break; break;
case FloatingCursorDragState.End: case FloatingCursorDragState.End:
// We skip animation if no update has happened. // We skip animation if no update has happened.
@ -259,10 +257,10 @@ mixin RawEditorStateTextInputClientMixin on EditorState
/// and current position of background cursor) /// and current position of background cursor)
void onFloatingCursorResetTick() { void onFloatingCursorResetTick() {
final finalPosition = final finalPosition =
getRenderEditor().getLocalRectForCaret(_lastTextPosition!).centerLeft - renderEditor.getLocalRectForCaret(_lastTextPosition!).centerLeft -
_floatingCursorOffset(_lastTextPosition!); _floatingCursorOffset(_lastTextPosition!);
if (floatingCursorResetController.isCompleted) { if (floatingCursorResetController.isCompleted) {
getRenderEditor().setFloatingCursor( renderEditor.setFloatingCursor(
FloatingCursorDragState.End, finalPosition, _lastTextPosition!); FloatingCursorDragState.End, finalPosition, _lastTextPosition!);
_startCaretRect = null; _startCaretRect = null;
_lastTextPosition = null; _lastTextPosition = null;
@ -275,7 +273,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
final lerpY = final lerpY =
lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!; lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!;
getRenderEditor().setFloatingCursor(FloatingCursorDragState.Update, renderEditor.setFloatingCursor(FloatingCursorDragState.Update,
Offset(lerpX, lerpY), _lastTextPosition!, Offset(lerpX, lerpY), _lastTextPosition!,
resetLerpValue: lerpValue); resetLerpValue: lerpValue);
} }

Loading…
Cancel
Save