diff --git a/lib/common/widgets/text_field/cupertino/cupertino_text_field.dart b/lib/common/widgets/text_field/cupertino/cupertino_text_field.dart index d73184e0d..e0855fce9 100644 --- a/lib/common/widgets/text_field/cupertino/cupertino_text_field.dart +++ b/lib/common/widgets/text_field/cupertino/cupertino_text_field.dart @@ -1732,7 +1732,6 @@ class _CupertinoRichTextFieldState extends State child: EditableText( key: editableTextKey, controller: controller, - undoController: widget.undoController, readOnly: widget.readOnly || !enabled, toolbarOptions: widget.toolbarOptions, showCursor: widget.showCursor, diff --git a/lib/common/widgets/text_field/editable_text.dart b/lib/common/widgets/text_field/editable_text.dart index ee514e125..39d6f18de 100644 --- a/lib/common/widgets/text_field/editable_text.dart +++ b/lib/common/widgets/text_field/editable_text.dart @@ -586,7 +586,6 @@ class EditableText extends StatefulWidget { this.contextMenuBuilder, this.spellCheckConfiguration, this.magnifierConfiguration = TextMagnifierConfiguration.disabled, - this.undoController, }) : assert(obscuringCharacter.length == 1), smartDashesType = smartDashesType ?? @@ -754,11 +753,6 @@ class EditableText extends StatefulWidget { /// The text style to use for the editable text. final TextStyle style; - /// Controls the undo state of the current editable text. - /// - /// If null, this widget will create its own [UndoHistoryController]. - final UndoHistoryController? undoController; - /// {@template flutter.widgets.editableText.strutStyle} /// The strut style used for the vertical layout. /// @@ -1984,163 +1978,165 @@ class EditableText extends StatefulWidget { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add( - DiagnosticsProperty('controller', controller), - ); - properties.add(DiagnosticsProperty('focusNode', focusNode)); - properties.add( - DiagnosticsProperty( - 'obscureText', - obscureText, - defaultValue: false, - ), - ); - properties.add( - DiagnosticsProperty('readOnly', readOnly, defaultValue: false), - ); - properties.add( - DiagnosticsProperty('autocorrect', autocorrect, defaultValue: true), - ); - properties.add( - EnumProperty( - 'smartDashesType', - smartDashesType, - defaultValue: obscureText - ? SmartDashesType.disabled - : SmartDashesType.enabled, - ), - ); - properties.add( - EnumProperty( - 'smartQuotesType', - smartQuotesType, - defaultValue: obscureText - ? SmartQuotesType.disabled - : SmartQuotesType.enabled, - ), - ); - properties.add( - DiagnosticsProperty( - 'enableSuggestions', - enableSuggestions, - defaultValue: true, - ), - ); + properties + ..add( + DiagnosticsProperty( + 'controller', + controller, + ), + ) + ..add(DiagnosticsProperty('focusNode', focusNode)) + ..add( + DiagnosticsProperty( + 'obscureText', + obscureText, + defaultValue: false, + ), + ) + ..add( + DiagnosticsProperty('readOnly', readOnly, defaultValue: false), + ) + ..add( + DiagnosticsProperty( + 'autocorrect', + autocorrect, + defaultValue: true, + ), + ) + ..add( + EnumProperty( + 'smartDashesType', + smartDashesType, + defaultValue: obscureText + ? SmartDashesType.disabled + : SmartDashesType.enabled, + ), + ) + ..add( + EnumProperty( + 'smartQuotesType', + smartQuotesType, + defaultValue: obscureText + ? SmartQuotesType.disabled + : SmartQuotesType.enabled, + ), + ) + ..add( + DiagnosticsProperty( + 'enableSuggestions', + enableSuggestions, + defaultValue: true, + ), + ); style.debugFillProperties(properties); - properties.add( - EnumProperty('textAlign', textAlign, defaultValue: null), - ); - properties.add( - EnumProperty( - 'textDirection', - textDirection, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty('locale', locale, defaultValue: null), - ); - properties.add( - DiagnosticsProperty( - 'textScaler', - textScaler, - defaultValue: null, - ), - ); - properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); - properties.add(IntProperty('minLines', minLines, defaultValue: null)); - properties.add( - DiagnosticsProperty('expands', expands, defaultValue: false), - ); - properties.add( - DiagnosticsProperty('autofocus', autofocus, defaultValue: false), - ); - properties.add( - DiagnosticsProperty( - 'keyboardType', - keyboardType, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty( - 'scrollController', - scrollController, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty( - 'scrollPhysics', - scrollPhysics, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty>( - 'autofillHints', - autofillHints, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty( - 'textHeightBehavior', - textHeightBehavior, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty( - 'scribbleEnabled', - scribbleEnabled, - defaultValue: true, - ), - ); - properties.add( - DiagnosticsProperty( - 'stylusHandwritingEnabled', - stylusHandwritingEnabled, - defaultValue: defaultStylusHandwritingEnabled, - ), - ); - properties.add( - DiagnosticsProperty( - 'enableIMEPersonalizedLearning', - enableIMEPersonalizedLearning, - defaultValue: true, - ), - ); - properties.add( - DiagnosticsProperty( - 'enableInteractiveSelection', - enableInteractiveSelection, - defaultValue: true, - ), - ); - properties.add( - DiagnosticsProperty( - 'undoController', - undoController, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty( - 'spellCheckConfiguration', - spellCheckConfiguration, - defaultValue: null, - ), - ); - properties.add( - DiagnosticsProperty>( - 'contentCommitMimeTypes', - contentInsertionConfiguration?.allowedMimeTypes ?? const [], - defaultValue: contentInsertionConfiguration == null - ? const [] - : kDefaultContentInsertionMimeTypes, - ), - ); + properties + ..add( + EnumProperty('textAlign', textAlign, defaultValue: null), + ) + ..add( + EnumProperty( + 'textDirection', + textDirection, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty('locale', locale, defaultValue: null), + ) + ..add( + DiagnosticsProperty( + 'textScaler', + textScaler, + defaultValue: null, + ), + ) + ..add(IntProperty('maxLines', maxLines, defaultValue: 1)) + ..add(IntProperty('minLines', minLines, defaultValue: null)) + ..add( + DiagnosticsProperty('expands', expands, defaultValue: false), + ) + ..add( + DiagnosticsProperty('autofocus', autofocus, defaultValue: false), + ) + ..add( + DiagnosticsProperty( + 'keyboardType', + keyboardType, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty( + 'scrollController', + scrollController, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty( + 'scrollPhysics', + scrollPhysics, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty>( + 'autofillHints', + autofillHints, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty( + 'textHeightBehavior', + textHeightBehavior, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty( + 'scribbleEnabled', + scribbleEnabled, + defaultValue: true, + ), + ) + ..add( + DiagnosticsProperty( + 'stylusHandwritingEnabled', + stylusHandwritingEnabled, + defaultValue: defaultStylusHandwritingEnabled, + ), + ) + ..add( + DiagnosticsProperty( + 'enableIMEPersonalizedLearning', + enableIMEPersonalizedLearning, + defaultValue: true, + ), + ) + ..add( + DiagnosticsProperty( + 'enableInteractiveSelection', + enableInteractiveSelection, + defaultValue: true, + ), + ) + ..add( + DiagnosticsProperty( + 'spellCheckConfiguration', + spellCheckConfiguration, + defaultValue: null, + ), + ) + ..add( + DiagnosticsProperty>( + 'contentCommitMimeTypes', + contentInsertionConfiguration?.allowedMimeTypes ?? const [], + defaultValue: contentInsertionConfiguration == null + ? const [] + : kDefaultContentInsertionMimeTypes, + ), + ); } } @@ -5813,178 +5809,123 @@ class EditableTextState extends State debugLabel: kReleaseMode ? null : 'EditableText', child: MouseRegion( cursor: widget.mouseCursor ?? SystemMouseCursors.text, - child: UndoHistory( - value: widget.controller, - onTriggered: (TextEditingValue value) { - userUpdateTextEditingValue( - value, - SelectionChangedCause.keyboard, - ); - }, - shouldChangeUndoStack: - (TextEditingValue? oldValue, TextEditingValue newValue) { - if (!newValue.selection.isValid) { - return false; - } - - if (oldValue == null) { - return true; - } - - switch (defaultTargetPlatform) { - case TargetPlatform.iOS: - case TargetPlatform.macOS: - case TargetPlatform.fuchsia: - case TargetPlatform.linux: - case TargetPlatform.windows: - // Composing text is not counted in history coalescing. - if (!widget - .controller - .value - .composing - .isCollapsed) { - return false; - } - case TargetPlatform.android: - // Gboard on Android puts non-CJK words in composing regions. Coalesce - // composing text in order to allow the saving of partial words in that - // case. - break; - } - - return oldValue.text != newValue.text || - oldValue.composing != newValue.composing; - }, - undoStackModifier: (TextEditingValue value) { - // On Android we should discard the composing region when pushing - // a new entry to the undo stack. This prevents the TextInputPlugin - // from restarting the input on every undo/redo when the composing - // region is changed by the framework. - return defaultTargetPlatform == TargetPlatform.android - ? value.copyWith(composing: TextRange.empty) - : value; - }, + child: Focus( focusNode: widget.focusNode, - controller: widget.undoController, - child: Focus( - focusNode: widget.focusNode, - includeSemantics: false, - debugLabel: kReleaseMode ? null : 'EditableText', - child: NotificationListener( - onNotification: (ScrollNotification notification) { - _handleContextMenuOnScroll(notification); - _scribbleCacheKey = null; - return false; - }, - child: Scrollable( - key: _scrollableKey, - excludeFromSemantics: true, - axisDirection: _isMultiline - ? AxisDirection.down - : AxisDirection.right, - controller: _scrollController, - physics: widget.scrollPhysics, - dragStartBehavior: widget.dragStartBehavior, - restorationId: widget.restorationId, - // If a ScrollBehavior is not provided, only apply scrollbars when - // multiline. The overscroll indicator should not be applied in - // either case, glowing or stretching. - scrollBehavior: - widget.scrollBehavior ?? - ScrollConfiguration.of( - context, - ).copyWith( - scrollbars: _isMultiline, - overscroll: false, - ), - viewportBuilder: - (BuildContext context, ViewportOffset offset) { - return CompositedTransformTarget( - link: _toolbarLayerLink, - child: Semantics( - inputType: inputType, - onCopy: _semanticsOnCopy(controls), - onCut: _semanticsOnCut(controls), - onPaste: _semanticsOnPaste(controls), - child: _ScribbleFocusable( - editableKey: _editableKey, - enabled: _stylusHandwritingEnabled, - focusNode: widget.focusNode, - updateSelectionRects: () { - _openInputConnection(); - _updateSelectionRects(force: true); - }, - child: SizeChangedLayoutNotifier( - child: _Editable( - key: _editableKey, - controller: widget.controller, - startHandleLayerLink: - _startHandleLayerLink, - endHandleLayerLink: _endHandleLayerLink, - inlineSpan: buildTextSpan(), - value: _value, - cursorColor: _cursorColor, - backgroundCursorColor: - widget.backgroundCursorColor, - showCursor: _cursorVisibilityNotifier, - forceLine: widget.forceLine, - readOnly: widget.readOnly, - hasFocus: _hasFocus, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - strutStyle: widget.strutStyle, - selectionColor: - _selectionOverlay - ?.spellCheckToolbarIsVisible ?? - false - ? _spellCheckConfiguration - .misspelledSelectionColor ?? - widget.selectionColor - : widget.selectionColor, - textScaler: effectiveTextScaler, - textAlign: widget.textAlign, - textDirection: _textDirection, - locale: widget.locale, - textHeightBehavior: - widget.textHeightBehavior ?? - DefaultTextHeightBehavior.maybeOf( - context, - ), - textWidthBasis: widget.textWidthBasis, - obscuringCharacter: - widget.obscuringCharacter, - obscureText: widget.obscureText, - offset: offset, - rendererIgnoresPointer: - widget.rendererIgnoresPointer, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorOffset: - widget.cursorOffset ?? Offset.zero, - selectionHeightStyle: - widget.selectionHeightStyle, - selectionWidthStyle: - widget.selectionWidthStyle, - paintCursorAboveText: - widget.paintCursorAboveText, - enableInteractiveSelection: - widget._userSelectionEnabled, - textSelectionDelegate: this, - devicePixelRatio: _devicePixelRatio, - promptRectRange: - _currentPromptRectRange, - promptRectColor: - widget.autocorrectionTextRectColor, - clipBehavior: widget.clipBehavior, - ), + includeSemantics: false, + debugLabel: kReleaseMode ? null : 'EditableText', + child: NotificationListener( + onNotification: (ScrollNotification notification) { + _handleContextMenuOnScroll(notification); + _scribbleCacheKey = null; + return false; + }, + child: Scrollable( + key: _scrollableKey, + excludeFromSemantics: true, + axisDirection: _isMultiline + ? AxisDirection.down + : AxisDirection.right, + controller: _scrollController, + physics: widget.scrollPhysics, + dragStartBehavior: widget.dragStartBehavior, + restorationId: widget.restorationId, + // If a ScrollBehavior is not provided, only apply scrollbars when + // multiline. The overscroll indicator should not be applied in + // either case, glowing or stretching. + scrollBehavior: + widget.scrollBehavior ?? + ScrollConfiguration.of( + context, + ).copyWith( + scrollbars: _isMultiline, + overscroll: false, + ), + viewportBuilder: + (BuildContext context, ViewportOffset offset) { + return CompositedTransformTarget( + link: _toolbarLayerLink, + child: Semantics( + inputType: inputType, + onCopy: _semanticsOnCopy(controls), + onCut: _semanticsOnCut(controls), + onPaste: _semanticsOnPaste(controls), + child: _ScribbleFocusable( + editableKey: _editableKey, + enabled: _stylusHandwritingEnabled, + focusNode: widget.focusNode, + updateSelectionRects: () { + _openInputConnection(); + _updateSelectionRects(force: true); + }, + child: SizeChangedLayoutNotifier( + child: _Editable( + key: _editableKey, + controller: widget.controller, + startHandleLayerLink: + _startHandleLayerLink, + endHandleLayerLink: _endHandleLayerLink, + inlineSpan: buildTextSpan(), + value: _value, + cursorColor: _cursorColor, + backgroundCursorColor: + widget.backgroundCursorColor, + showCursor: _cursorVisibilityNotifier, + forceLine: widget.forceLine, + readOnly: widget.readOnly, + hasFocus: _hasFocus, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + strutStyle: widget.strutStyle, + selectionColor: + _selectionOverlay + ?.spellCheckToolbarIsVisible ?? + false + ? _spellCheckConfiguration + .misspelledSelectionColor ?? + widget.selectionColor + : widget.selectionColor, + textScaler: effectiveTextScaler, + textAlign: widget.textAlign, + textDirection: _textDirection, + locale: widget.locale, + textHeightBehavior: + widget.textHeightBehavior ?? + DefaultTextHeightBehavior.maybeOf( + context, + ), + textWidthBasis: widget.textWidthBasis, + obscuringCharacter: + widget.obscuringCharacter, + obscureText: widget.obscureText, + offset: offset, + rendererIgnoresPointer: + widget.rendererIgnoresPointer, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorOffset: + widget.cursorOffset ?? Offset.zero, + selectionHeightStyle: + widget.selectionHeightStyle, + selectionWidthStyle: + widget.selectionWidthStyle, + paintCursorAboveText: + widget.paintCursorAboveText, + enableInteractiveSelection: + widget._userSelectionEnabled, + textSelectionDelegate: this, + devicePixelRatio: _devicePixelRatio, + promptRectRange: _currentPromptRectRange, + promptRectColor: + widget.autocorrectionTextRectColor, + clipBehavior: widget.clipBehavior, ), ), ), - ); - }, - ), + ), + ); + }, ), ), ), diff --git a/lib/common/widgets/text_field/text_field.dart b/lib/common/widgets/text_field/text_field.dart index 0dfc89166..d34ff3f8e 100644 --- a/lib/common/widgets/text_field/text_field.dart +++ b/lib/common/widgets/text_field/text_field.dart @@ -273,7 +273,6 @@ class RichTextField extends StatefulWidget { this.groupId = EditableText, required this.controller, this.focusNode, - this.undoController, this.decoration = const InputDecoration(), TextInputType? keyboardType, this.textInputAction, @@ -884,9 +883,6 @@ class RichTextField extends StatefulWidget { /// be possible to move the focus to the text field with tab key. final bool canRequestFocus; - /// {@macro flutter.widgets.undoHistory.controller} - final UndoHistoryController? undoController; - static Widget _defaultContextMenuBuilder( BuildContext context, EditableTextState editableTextState, @@ -995,13 +991,6 @@ class RichTextField extends StatefulWidget { defaultValue: null, ), ) - ..add( - DiagnosticsProperty( - 'undoController', - undoController, - defaultValue: null, - ), - ) ..add(DiagnosticsProperty('enabled', enabled, defaultValue: null)) ..add( DiagnosticsProperty( @@ -1840,7 +1829,6 @@ class RichTextFieldState extends State showSelectionHandles: _showSelectionHandles, controller: controller, focusNode: focusNode, - undoController: widget.undoController, keyboardType: widget.keyboardType, textInputAction: widget.textInputAction, textCapitalization: widget.textCapitalization,