From 20262740cf556b17a51d6e3d500773c0e27d3512 Mon Sep 17 00:00:00 2001 From: xuyang Date: Tue, 20 Aug 2024 09:08:04 +0800 Subject: [PATCH] [chore]: change gesture --- .../editor/raw_editor/raw_editor_state.dart | 281 ++++++------------ lib/src/editor/widgets/delegate.dart | 5 +- 2 files changed, 93 insertions(+), 193 deletions(-) diff --git a/lib/src/editor/raw_editor/raw_editor_state.dart b/lib/src/editor/raw_editor/raw_editor_state.dart index 300b6d39..fccddbfc 100644 --- a/lib/src/editor/raw_editor/raw_editor_state.dart +++ b/lib/src/editor/raw_editor/raw_editor_state.dart @@ -9,15 +9,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart' show RenderAbstractViewport; import 'package:flutter/scheduler.dart' show SchedulerBinding; import 'package:flutter/services.dart' - show - Clipboard, - HardwareKeyboard, - KeyDownEvent, - LogicalKeyboardKey, - SystemChannels, - TextInputControl; -import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart' - show KeyboardVisibilityController; + show Clipboard, HardwareKeyboard, KeyDownEvent, LogicalKeyboardKey, SystemChannels, TextInputControl; +import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart' show KeyboardVisibilityController; import '../../common/structs/horizontal_spacing.dart'; import '../../common/structs/offset_value.dart'; @@ -107,11 +100,8 @@ class QuillRawEditorState extends EditorState @override void insertContent(KeyboardInsertedContent content) { - assert(widget.configurations.contentInsertionConfiguration?.allowedMimeTypes - .contains(content.mimeType) ?? - false); - widget.configurations.contentInsertionConfiguration?.onContentInserted - .call(content); + assert(widget.configurations.contentInsertionConfiguration?.allowedMimeTypes.contains(content.mimeType) ?? false); + widget.configurations.contentInsertionConfiguration?.onContentInserted.call(content); } /// Copy current selection to [Clipboard]. @@ -127,8 +117,7 @@ class QuillRawEditorState extends EditorState userUpdateTextEditingValue( TextEditingValue( text: textEditingValue.text, - selection: - TextSelection.collapsed(offset: textEditingValue.selection.end), + selection: TextSelection.collapsed(offset: textEditingValue.selection.end), ), SelectionChangedCause.toolbar, ); @@ -202,8 +191,7 @@ class QuillRawEditorState extends EditorState void selectAll(SelectionChangedCause cause) { userUpdateTextEditingValue( textEditingValue.copyWith( - selection: TextSelection( - baseOffset: 0, extentOffset: textEditingValue.text.length), + selection: TextSelection(baseOffset: 0, extentOffset: textEditingValue.text.length), ), cause, ); @@ -218,27 +206,14 @@ class QuillRawEditorState extends EditorState /// Copied from [EditableTextState]. List get contextMenuButtonItems { return EditableText.getEditableButtonItems( - clipboardStatus: - (_clipboardStatus != null) ? _clipboardStatus!.value : null, - onCopy: copyEnabled - ? () => copySelection(SelectionChangedCause.toolbar) - : null, - onCut: - cutEnabled ? () => cutSelection(SelectionChangedCause.toolbar) : null, - onPaste: - pasteEnabled ? () => pasteText(SelectionChangedCause.toolbar) : null, - onSelectAll: selectAllEnabled - ? () => selectAll(SelectionChangedCause.toolbar) - : null, - onLookUp: lookUpEnabled - ? () => lookUpSelection(SelectionChangedCause.toolbar) - : null, - onSearchWeb: searchWebEnabled - ? () => searchWebForSelection(SelectionChangedCause.toolbar) - : null, - onShare: shareEnabled - ? () => shareSelection(SelectionChangedCause.toolbar) - : null, + clipboardStatus: (_clipboardStatus != null) ? _clipboardStatus!.value : null, + onCopy: copyEnabled ? () => copySelection(SelectionChangedCause.toolbar) : null, + onCut: cutEnabled ? () => cutSelection(SelectionChangedCause.toolbar) : null, + onPaste: pasteEnabled ? () => pasteText(SelectionChangedCause.toolbar) : null, + onSelectAll: selectAllEnabled ? () => selectAll(SelectionChangedCause.toolbar) : null, + onLookUp: lookUpEnabled ? () => lookUpSelection(SelectionChangedCause.toolbar) : null, + onSearchWeb: searchWebEnabled ? () => searchWebForSelection(SelectionChangedCause.toolbar) : null, + onShare: shareEnabled ? () => shareSelection(SelectionChangedCause.toolbar) : null, onLiveTextInput: liveTextInputEnabled ? () {} : null, ); } @@ -332,10 +307,8 @@ class QuillRawEditorState extends EditorState ); } - final startCharacterRect = - renderEditor.getLocalRectForCaret(selection.base); - final endCharacterRect = - renderEditor.getLocalRectForCaret(selection.extent); + final startCharacterRect = renderEditor.getLocalRectForCaret(selection.base); + final endCharacterRect = renderEditor.getLocalRectForCaret(selection.extent); return QuillEditorGlyphHeights( startCharacterRect.height, endCharacterRect.height, @@ -382,12 +355,9 @@ class QuillRawEditorState extends EditorState Widget _scribbleFocusable(Widget child) { return ScribbleFocusable( editorKey: _editorKey, - enabled: widget.configurations.enableScribble && - !widget.configurations.readOnly, - renderBoxForBounds: () => context - .findAncestorStateOfType() - ?.context - .findRenderObject() as RenderBox?, + enabled: widget.configurations.enableScribble && !widget.configurations.readOnly, + renderBoxForBounds: () => + context.findAncestorStateOfType()?.context.findRenderObject() as RenderBox?, onScribbleFocus: (offset) { widget.configurations.focusNode.requestFocus(); widget.configurations.onScribbleActivated?.call(); @@ -433,8 +403,7 @@ class QuillRawEditorState extends EditorState /// the scroll view with [BaselineProxy] which mimics the editor's /// baseline. // This implies that the first line has no styles applied to it. - final baselinePadding = - EdgeInsets.only(top: _styles!.paragraph!.verticalSpacing.top); + final baselinePadding = EdgeInsets.only(top: _styles!.paragraph!.verticalSpacing.top); child = BaselineProxy( textStyle: _styles!.paragraph!.style, padding: baselinePadding, @@ -464,8 +433,7 @@ class QuillRawEditorState extends EditorState padding: widget.configurations.padding, maxContentWidth: widget.configurations.maxContentWidth, cursorController: _cursorCont, - floatingCursorDisabled: - widget.configurations.floatingCursorDisabled, + floatingCursorDisabled: widget.configurations.floatingCursorDisabled, children: _buildChildren(doc, context), ), ), @@ -479,9 +447,8 @@ class QuillRawEditorState extends EditorState link: _toolbarLayerLink, child: Semantics( child: MouseRegion( - cursor: widget.configurations.readOnly - ? widget.configurations.readOnlyMouseCursor - : SystemMouseCursors.text, + cursor: + widget.configurations.readOnly ? widget.configurations.readOnlyMouseCursor : SystemMouseCursors.text, child: QuillRawEditorMultiChildRenderObject( key: _editorKey, document: doc, @@ -497,8 +464,7 @@ class QuillRawEditorState extends EditorState scrollBottomInset: widget.configurations.scrollBottomInset, padding: widget.configurations.padding, maxContentWidth: widget.configurations.maxContentWidth, - floatingCursorDisabled: - widget.configurations.floatingCursorDisabled, + floatingCursorDisabled: widget.configurations.floatingCursorDisabled, children: _buildChildren(doc, context), ), ), @@ -708,15 +674,12 @@ class QuillRawEditorState extends EditorState LogicalKeyboardKey.pageUp, control: !isDesktopMacOS, meta: isDesktopMacOS, - ): const ScrollIntent( - direction: AxisDirection.up, type: ScrollIncrementType.page), + ): const ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), SingleActivator( LogicalKeyboardKey.pageDown, control: !isDesktopMacOS, meta: isDesktopMacOS, - ): const ScrollIntent( - direction: AxisDirection.down, - type: ScrollIncrementType.page), + ): const ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), }, ), child: Actions( @@ -770,8 +733,7 @@ class QuillRawEditorState extends EditorState } KeyEventResult _handleSpaceKey(KeyEvent event) { - final child = - controller.document.queryChild(controller.selection.baseOffset); + final child = controller.document.queryChild(controller.selection.baseOffset); if (child.node == null) { return KeyEventResult.ignored; } @@ -788,8 +750,7 @@ class QuillRawEditorState extends EditorState const olKeyPhrase = '1.'; const ulKeyPhrase = '-'; - final enableMdConversion = - widget.configurations.enableMarkdownStyleConversion; + final enableMdConversion = widget.configurations.enableMarkdownStyleConversion; if (text.value == olKeyPhrase && enableMdConversion) { _updateSelectionForKeyPhrase(olKeyPhrase, Attribute.ol); @@ -803,8 +764,7 @@ class QuillRawEditorState extends EditorState } KeyEventResult _handleTabKey(KeyEvent event) { - final child = - controller.document.queryChild(controller.selection.baseOffset); + final child = controller.document.queryChild(controller.selection.baseOffset); KeyEventResult insertTabCharacter() { if (widget.configurations.readOnly) { @@ -866,23 +826,20 @@ class QuillRawEditorState extends EditorState void _moveCursor(int chars) { final selection = controller.selection; controller.updateSelection( - controller.selection.copyWith( - baseOffset: selection.baseOffset + chars, - extentOffset: selection.baseOffset + chars), + controller.selection + .copyWith(baseOffset: selection.baseOffset + chars, extentOffset: selection.baseOffset + chars), ChangeSource.local); } void _updateSelectionForKeyPhrase(String phrase, Attribute attribute) { - controller.replaceText(controller.selection.baseOffset - phrase.length, - phrase.length, '\n', null); + controller.replaceText(controller.selection.baseOffset - phrase.length, phrase.length, '\n', null); _moveCursor(-phrase.length); controller ..formatSelection(attribute) // Remove the added newline. ..replaceText(controller.selection.baseOffset + 1, 1, '', null); // - final style = - controller.document.collectStyle(controller.selection.baseOffset, 0); + final style = controller.document.collectStyle(controller.selection.baseOffset, 0); if (style.isNotEmpty) { for (final attr in style.values) { controller.formatSelection(attr); @@ -930,10 +887,8 @@ class QuillRawEditorState extends EditorState /// Updates the checkbox positioned at [offset] in document /// by changing its attribute according to [value]. void _handleCheckboxTap(int offset, bool value) { - final requestKeyboardFocusOnCheckListChanged = - widget.configurations.requestKeyboardFocusOnCheckListChanged; - if (!(widget.configurations.checkBoxReadOnly ?? - widget.configurations.readOnly)) { + final requestKeyboardFocusOnCheckListChanged = widget.configurations.requestKeyboardFocusOnCheckListChanged; + if (!(widget.configurations.checkBoxReadOnly ?? widget.configurations.readOnly)) { _disableScrollControllerAnimateOnce = true; final currentSelection = controller.selection.copyWith(); final attribute = value ? Attribute.checked : Attribute.unchecked; @@ -946,10 +901,7 @@ class QuillRawEditorState extends EditorState // Checkbox tapping causes controller.selection to go to offset 0 // Stop toggling those two toolbar buttons - ..toolbarButtonToggler = { - Attribute.list.key: attribute, - Attribute.header.key: Attribute.header - }; + ..toolbarButtonToggler = {Attribute.list.key: attribute, Attribute.header.key: Attribute.header}; // Go back from offset 0 to current selection SchedulerBinding.instance.addPostFrameCallback((_) { @@ -985,14 +937,12 @@ class QuillRawEditorState extends EditorState // and watch if the system language is a RTL language and avoid putting // to the edge of the left side any checkbox or list point/number if is a // RTL language - if (nodeTextDirection == TextDirection.ltr && - _textDirection == TextDirection.rtl) { + if (nodeTextDirection == TextDirection.ltr && _textDirection == TextDirection.rtl) { nodeTextDirection = TextDirection.rtl; } if (node is Line) { final editableTextLine = _getEditableTextLineFromNode(node, context); - result.add(Directionality( - textDirection: nodeTextDirection, child: editableTextLine)); + result.add(Directionality(textDirection: nodeTextDirection, child: editableTextLine)); } else if (node is Block) { final editableTextBlock = EditableTextBlock( block: node, @@ -1004,12 +954,9 @@ class QuillRawEditorState extends EditorState textSelection: controller.selection, color: widget.configurations.selectionColor, styles: _styles, - enableInteractiveSelection: - widget.configurations.enableInteractiveSelection, + enableInteractiveSelection: widget.configurations.enableInteractiveSelection, hasFocus: _hasFocus, - contentPadding: attrs.containsKey(Attribute.codeBlock.key) - ? const EdgeInsets.all(16) - : null, + contentPadding: attrs.containsKey(Attribute.codeBlock.key) ? const EdgeInsets.all(16) : null, embedBuilder: widget.configurations.embedBuilder, linkActionPicker: _linkActionPicker, onLaunchUrl: widget.configurations.onLaunchUrl, @@ -1039,8 +986,7 @@ class QuillRawEditorState extends EditorState return result; } - EditableTextLine _getEditableTextLineFromNode( - Line node, BuildContext context) { + EditableTextLine _getEditableTextLineFromNode(Line node, BuildContext context) { final textLine = TextLine( line: node, textDirection: _textDirection, @@ -1136,8 +1082,7 @@ class QuillRawEditorState extends EditorState return defaultStyles!.paragraph!.verticalSpacing; } - HorizontalSpacing _getHorizontalSpacingForBlock( - Block node, DefaultStyles? defaultStyles) { + HorizontalSpacing _getHorizontalSpacingForBlock(Block node, DefaultStyles? defaultStyles) { final attrs = node.style.attributes; if (attrs.containsKey(Attribute.blockQuote.key)) { return defaultStyles!.quote!.horizontalSpacing; @@ -1153,8 +1098,7 @@ class QuillRawEditorState extends EditorState return HorizontalSpacing.zero; } - VerticalSpacing _getVerticalSpacingForBlock( - Block node, DefaultStyles? defaultStyles) { + VerticalSpacing _getVerticalSpacingForBlock(Block node, DefaultStyles? defaultStyles) { final attrs = node.style.attributes; if (attrs.containsKey(Attribute.blockQuote.key)) { return defaultStyles!.quote!.verticalSpacing; @@ -1209,8 +1153,7 @@ class QuillRawEditorState extends EditorState } else { _keyboardVisibilityController = KeyboardVisibilityController(); _keyboardVisible = _keyboardVisibilityController!.isVisible; - _keyboardVisibilitySubscription = - _keyboardVisibilityController?.onChange.listen((visible) { + _keyboardVisibilitySubscription = _keyboardVisibilityController?.onChange.listen((visible) { _keyboardVisible = visible; if (visible) { _onChangeTextEditingValue(!_hasFocus); @@ -1252,9 +1195,7 @@ class QuillRawEditorState extends EditorState super.didChangeDependencies(); final parentStyles = QuillStyles.getStyles(context, true); final defaultStyles = DefaultStyles.getInstance(context); - _styles = (parentStyles != null) - ? defaultStyles.merge(parentStyles) - : defaultStyles; + _styles = (parentStyles != null) ? defaultStyles.merge(parentStyles) : defaultStyles; if (widget.configurations.customStyles != null) { _styles = _styles!.merge(widget.configurations.customStyles!); @@ -1317,8 +1258,7 @@ class QuillRawEditorState extends EditorState } bool _shouldShowSelectionHandles() { - return widget.configurations.showSelectionHandles && - !controller.selection.isCollapsed; + return widget.configurations.showSelectionHandles && !controller.selection.isCollapsed; } @override @@ -1419,10 +1359,7 @@ class QuillRawEditorState extends EditorState void _updateOrDisposeSelectionOverlayIfNeeded() { if (_selectionOverlay != null) { - if (!_hasFocus || textEditingValue.selection.isCollapsed) { - _selectionOverlay?.dispose(); - _selectionOverlay = null; - } else if (_hasFocus) { + if (_hasFocus) { _selectionOverlay!.update(textEditingValue); } else { _selectionOverlay!.dispose(); @@ -1448,18 +1385,16 @@ class QuillRawEditorState extends EditorState clipboardStatus: _clipboardStatus, contextMenuBuilder: widget.configurations.contextMenuBuilder == null ? null - : (context) => - widget.configurations.contextMenuBuilder!(context, this), - magnifierConfiguration: widget.configurations.magnifierConfiguration ?? - TextMagnifier.adaptiveMagnifierConfiguration, + : (context) => widget.configurations.contextMenuBuilder!(context, this), + magnifierConfiguration: + widget.configurations.magnifierConfiguration ?? TextMagnifier.adaptiveMagnifierConfiguration, ); } void _handleFocusChanged() { if (dirty) { requestKeyboard(); - SchedulerBinding.instance - .addPostFrameCallback((_) => _handleFocusChanged()); + SchedulerBinding.instance.addPostFrameCallback((_) => _handleFocusChanged()); return; } openOrCloseConnection(); @@ -1483,8 +1418,7 @@ class QuillRawEditorState extends EditorState Future _linkActionPicker(Node linkNode) async { final link = linkNode.style.attributes[Attribute.link.key]!.value!; - return widget.configurations - .linkActionPickerDelegate(context, link, linkNode); + return widget.configurations.linkActionPickerDelegate(context, link, linkNode); } bool _showCaretOnScreenScheduled = false; @@ -1511,8 +1445,7 @@ class QuillRawEditorState extends EditorState } final viewport = RenderAbstractViewport.of(renderEditor); - final editorOffset = - renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport); + final editorOffset = renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport); final offsetInViewport = _scrollController.offset + editorOffset.dy; final offset = renderEditor.getOffsetToRevealCursor( @@ -1540,8 +1473,7 @@ class QuillRawEditorState extends EditorState /// /// This property is typically used to notify the renderer of input gestures. @override - RenderEditor get renderEditor => - _editorKey.currentContext!.findRenderObject() as RenderEditor; + RenderEditor get renderEditor => _editorKey.currentContext!.findRenderObject() as RenderEditor; /// Express interest in interacting with the keyboard. /// @@ -1616,8 +1548,7 @@ class QuillRawEditorState extends EditorState void _replaceText(ReplaceTextIntent intent) { userUpdateTextEditingValue( - intent.currentTextEditingValue - .replaced(intent.replacementRange, intent.replacementText), + intent.currentTextEditingValue.replaced(intent.replacementRange, intent.replacementText), intent.cause, ); } @@ -1626,22 +1557,18 @@ class QuillRawEditorState extends EditorState bool get wantKeepAlive => widget.configurations.focusNode.hasFocus; @override - AnimationController get floatingCursorResetController => - _floatingCursorResetController; + AnimationController get floatingCursorResetController => _floatingCursorResetController; late AnimationController _floatingCursorResetController; // --------------------------- Text Editing Actions -------------------------- - QuillEditorTextBoundary _characterBoundary( - DirectionalTextEditingIntent intent) { + QuillEditorTextBoundary _characterBoundary(DirectionalTextEditingIntent intent) { final atomicTextBoundary = QuillEditorCharacterBoundary(textEditingValue); - return QuillEditorCollapsedSelectionBoundary( - atomicTextBoundary, intent.forward); + return QuillEditorCollapsedSelectionBoundary(atomicTextBoundary, intent.forward); } - QuillEditorTextBoundary _nextWordBoundary( - DirectionalTextEditingIntent intent) { + QuillEditorTextBoundary _nextWordBoundary(DirectionalTextEditingIntent intent) { final QuillEditorTextBoundary atomicTextBoundary; final QuillEditorTextBoundary boundary; @@ -1650,8 +1577,7 @@ class QuillRawEditorState extends EditorState atomicTextBoundary = QuillEditorCharacterBoundary(textEditingValue); // This isn't enough. Newline characters. boundary = QuillEditorExpandedTextBoundary( - QuillEditorWhitespaceBoundary(textEditingValue), - QuillEditorWordBoundary(renderEditor, textEditingValue)); + QuillEditorWhitespaceBoundary(textEditingValue), QuillEditorWordBoundary(renderEditor, textEditingValue)); final mixedBoundary = intent.forward ? QuillEditorMixedBoundary(atomicTextBoundary, boundary) @@ -1676,26 +1602,21 @@ class QuillRawEditorState extends EditorState // since the document boundary is unique and the linebreak boundary is // already caret-location based. return intent.forward - ? QuillEditorMixedBoundary( - QuillEditorCollapsedSelectionBoundary(atomicTextBoundary, true), - boundary) + ? QuillEditorMixedBoundary(QuillEditorCollapsedSelectionBoundary(atomicTextBoundary, true), boundary) : QuillEditorMixedBoundary( boundary, QuillEditorCollapsedSelectionBoundary(atomicTextBoundary, false), ); } - QuillEditorTextBoundary _documentBoundary( - DirectionalTextEditingIntent intent) => + QuillEditorTextBoundary _documentBoundary(DirectionalTextEditingIntent intent) => QuillEditorDocumentBoundary(textEditingValue); Action _makeOverridable(Action defaultAction) { - return Action.overridable( - context: context, defaultAction: defaultAction); + return Action.overridable(context: context, defaultAction: defaultAction); } - late final Action _replaceTextAction = - CallbackAction(onInvoke: _replaceText); + late final Action _replaceTextAction = CallbackAction(onInvoke: _replaceText); void _updateSelection(UpdateSelectionIntent intent) { userUpdateTextEditingValue( @@ -1707,27 +1628,20 @@ class QuillRawEditorState extends EditorState late final Action _updateSelectionAction = CallbackAction(onInvoke: _updateSelection); - late final QuillEditorUpdateTextSelectionToAdjacentLineAction< - ExtendSelectionVerticallyToAdjacentLineIntent> _adjacentLineAction = - QuillEditorUpdateTextSelectionToAdjacentLineAction< - ExtendSelectionVerticallyToAdjacentLineIntent>(this); + late final QuillEditorUpdateTextSelectionToAdjacentLineAction + _adjacentLineAction = + QuillEditorUpdateTextSelectionToAdjacentLineAction(this); late final _adjacentPageAction = - QuillEditorUpdateTextSelectionToAdjacentPageAction< - ExtendSelectionVerticallyToAdjacentPageIntent>(this); + QuillEditorUpdateTextSelectionToAdjacentPageAction(this); - late final QuillEditorToggleTextStyleAction _formatSelectionAction = - QuillEditorToggleTextStyleAction(this); + late final QuillEditorToggleTextStyleAction _formatSelectionAction = QuillEditorToggleTextStyleAction(this); - late final QuillEditorIndentSelectionAction _indentSelectionAction = - QuillEditorIndentSelectionAction(this); + late final QuillEditorIndentSelectionAction _indentSelectionAction = QuillEditorIndentSelectionAction(this); - late final QuillEditorOpenSearchAction _openSearchAction = - QuillEditorOpenSearchAction(this); - late final QuillEditorApplyHeaderAction _applyHeaderAction = - QuillEditorApplyHeaderAction(this); - late final QuillEditorApplyCheckListAction _applyCheckListAction = - QuillEditorApplyCheckListAction(this); + late final QuillEditorOpenSearchAction _openSearchAction = QuillEditorOpenSearchAction(this); + late final QuillEditorApplyHeaderAction _applyHeaderAction = QuillEditorApplyHeaderAction(this); + late final QuillEditorApplyCheckListAction _applyCheckListAction = QuillEditorApplyCheckListAction(this); late final Map> _actions = >{ DoNothingAndStopPropagationTextIntent: DoNothingAction(consumesKey: false), @@ -1736,48 +1650,35 @@ class QuillRawEditorState extends EditorState DirectionalFocusIntent: DirectionalFocusAction.forTextField(), // Delete - DeleteCharacterIntent: _makeOverridable( - QuillEditorDeleteTextAction( - this, _characterBoundary)), - DeleteToNextWordBoundaryIntent: _makeOverridable( - QuillEditorDeleteTextAction( - this, _nextWordBoundary)), - DeleteToLineBreakIntent: _makeOverridable( - QuillEditorDeleteTextAction(this, _linebreak)), + DeleteCharacterIntent: + _makeOverridable(QuillEditorDeleteTextAction(this, _characterBoundary)), + DeleteToNextWordBoundaryIntent: + _makeOverridable(QuillEditorDeleteTextAction(this, _nextWordBoundary)), + DeleteToLineBreakIntent: _makeOverridable(QuillEditorDeleteTextAction(this, _linebreak)), // Extend/Move Selection - ExtendSelectionByCharacterIntent: _makeOverridable( - QuillEditorUpdateTextSelectionAction( + ExtendSelectionByCharacterIntent: + _makeOverridable(QuillEditorUpdateTextSelectionAction( this, false, _characterBoundary, )), ExtendSelectionToNextWordBoundaryIntent: _makeOverridable( - QuillEditorUpdateTextSelectionAction< - ExtendSelectionToNextWordBoundaryIntent>( - this, true, _nextWordBoundary)), + QuillEditorUpdateTextSelectionAction(this, true, _nextWordBoundary)), ExtendSelectionToLineBreakIntent: _makeOverridable( - QuillEditorUpdateTextSelectionAction( - this, true, _linebreak)), - ExtendSelectionVerticallyToAdjacentLineIntent: - _makeOverridable(_adjacentLineAction), + QuillEditorUpdateTextSelectionAction(this, true, _linebreak)), + ExtendSelectionVerticallyToAdjacentLineIntent: _makeOverridable(_adjacentLineAction), ExtendSelectionToDocumentBoundaryIntent: _makeOverridable( - QuillEditorUpdateTextSelectionAction< - ExtendSelectionToDocumentBoundaryIntent>( - this, true, _documentBoundary)), - ExtendSelectionToNextWordBoundaryOrCaretLocationIntent: _makeOverridable( - QuillEditorExtendSelectionOrCaretPositionAction( - this, _nextWordBoundary)), + QuillEditorUpdateTextSelectionAction(this, true, _documentBoundary)), + ExtendSelectionToNextWordBoundaryOrCaretLocationIntent: + _makeOverridable(QuillEditorExtendSelectionOrCaretPositionAction(this, _nextWordBoundary)), // Copy Paste SelectAllTextIntent: _makeOverridable(QuillEditorSelectAllAction(this)), - CopySelectionTextIntent: - _makeOverridable(QuillEditorCopySelectionAction(this)), - PasteTextIntent: _makeOverridable(CallbackAction( - onInvoke: (intent) => pasteText(intent.cause))), + CopySelectionTextIntent: _makeOverridable(QuillEditorCopySelectionAction(this)), + PasteTextIntent: _makeOverridable(CallbackAction(onInvoke: (intent) => pasteText(intent.cause))), - HideSelectionToolbarIntent: - _makeOverridable(QuillEditorHideSelectionToolbarAction(this)), + HideSelectionToolbarIntent: _makeOverridable(QuillEditorHideSelectionToolbarAction(this)), UndoTextIntent: _makeOverridable(QuillEditorUndoKeyboardAction(this)), RedoTextIntent: _makeOverridable(QuillEditorRedoKeyboardAction(this)), @@ -1851,10 +1752,8 @@ class QuillRawEditorState extends EditorState if (_hasFocus == false) return; if (_selectionOverlay == null) return; final position = renderEditor.getPositionForOffset(positionToShow); - _selectionOverlay?.showMagnifier(position, positionToShow, renderEditor); if (_selectionOverlay!.magnifierIsVisible) { - _selectionOverlay! - .updateMagnifier(position, positionToShow, renderEditor); + _selectionOverlay!.updateMagnifier(position, positionToShow, renderEditor); } else { _selectionOverlay!.showMagnifier(position, positionToShow, renderEditor); } diff --git a/lib/src/editor/widgets/delegate.dart b/lib/src/editor/widgets/delegate.dart index f51f74c4..dada7430 100644 --- a/lib/src/editor/widgets/delegate.dart +++ b/lib/src/editor/widgets/delegate.dart @@ -8,7 +8,7 @@ import 'package:flutter/services.dart'; import '../../common/utils/platform.dart'; import '../../document/attribute.dart'; import '../../document/nodes/leaf.dart'; -import '../../widgets/editor/editor.dart'; +import '../editor.dart'; import '../raw_editor/raw_editor.dart'; import 'text/text_selection.dart'; @@ -254,7 +254,8 @@ class EditorTextSelectionGestureDetectorBuilder { @protected void onTapDown(TapDragDownDetails details) { if (!delegate.selectionEnabled) return; - renderEditor!.handleTapDown(details); + renderEditor! + .handleTapDown(TapDownDetails(globalPosition: details.globalPosition)); final kind = details.kind; shouldShowSelectionToolbar = kind == null || kind == PointerDeviceKind.touch ||