[chore]: code fromatter

pull/2126/head
xuyang 8 months ago
parent 20262740cf
commit 9cf0630261
  1. 275
      lib/src/editor/raw_editor/raw_editor_state.dart

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

Loading…
Cancel
Save