From d48abe8ea77bd1fc1879791c9cdfb913277430d1 Mon Sep 17 00:00:00 2001 From: Miller Adulu Date: Sat, 13 Mar 2021 14:17:04 +0300 Subject: [PATCH] Fix formatting --- lib/models/documents/attribute.dart | 1 - lib/models/documents/nodes/embed.dart | 3 +-- lib/models/documents/nodes/leaf.dart | 3 +-- lib/models/documents/nodes/line.dart | 4 ++- lib/models/documents/style.dart | 4 +-- lib/models/quill_delta.dart | 21 ++++++++-------- lib/models/rules/insert.dart | 2 +- lib/utils/hashcode.dart | 2 +- lib/widgets/controller.dart | 29 +++++++++++---------- lib/widgets/cursor.dart | 3 +-- lib/widgets/default_styles.dart | 3 +-- lib/widgets/delegate.dart | 3 +-- lib/widgets/editor.dart | 36 +++++++++++++-------------- lib/widgets/keyboard_listener.dart | 3 +-- lib/widgets/raw_editor.dart | 32 ++++++++++++------------ lib/widgets/text_block.dart | 13 ++++------ lib/widgets/text_selection.dart | 13 +++------- lib/widgets/toolbar.dart | 30 ++++++++++------------ 18 files changed, 93 insertions(+), 112 deletions(-) diff --git a/lib/models/documents/attribute.dart b/lib/models/documents/attribute.dart index ef02b2b7..88f94f0e 100644 --- a/lib/models/documents/attribute.dart +++ b/lib/models/documents/attribute.dart @@ -1,4 +1,3 @@ - import 'package:flutter_quill/utils/hashcode.dart' as hashcode; enum AttributeScope { diff --git a/lib/models/documents/nodes/embed.dart b/lib/models/documents/nodes/embed.dart index ee8dfbed..3268e257 100644 --- a/lib/models/documents/nodes/embed.dart +++ b/lib/models/documents/nodes/embed.dart @@ -2,8 +2,7 @@ class Embeddable { final String type; final dynamic data; - Embeddable(this.type, this.data) - ; + Embeddable(this.type, this.data); Map toJson() { Map m = {type: data}; diff --git a/lib/models/documents/nodes/leaf.dart b/lib/models/documents/nodes/leaf.dart index b5c41f6b..804c9a10 100644 --- a/lib/models/documents/nodes/leaf.dart +++ b/lib/models/documents/nodes/leaf.dart @@ -26,8 +26,7 @@ abstract class Leaf extends Node { @override void applyStyle(Style value) { - assert( - (value.isInline || value.isIgnored || value.isEmpty), + assert((value.isInline || value.isIgnored || value.isEmpty), 'Unable to apply Style to leaf: $value'); super.applyStyle(value); } diff --git a/lib/models/documents/nodes/line.dart b/lib/models/documents/nodes/line.dart index fac501ba..4e3b1ac0 100644 --- a/lib/models/documents/nodes/line.dart +++ b/lib/models/documents/nodes/line.dart @@ -36,7 +36,9 @@ class Line extends Container { if (parent!.isLast) { return null; } - return parent!.next is Block ? (parent!.next as Block).first as Line? : parent!.next as Line?; + return parent!.next is Block + ? (parent!.next as Block).first as Line? + : parent!.next as Line?; } @override diff --git a/lib/models/documents/style.dart b/lib/models/documents/style.dart index 1e43ce2f..144cb038 100644 --- a/lib/models/documents/style.dart +++ b/lib/models/documents/style.dart @@ -100,8 +100,8 @@ class Style { @override int get hashCode { - final hashes = - _attributes.entries.map((entry) => hashcode.hash2(entry.key, entry.value)); + final hashes = _attributes.entries + .map((entry) => hashcode.hash2(entry.key, entry.value)); return hashcode.hashObjects(hashes); } diff --git a/lib/models/quill_delta.dart b/lib/models/quill_delta.dart index 4e61ed3d..f53f115c 100644 --- a/lib/models/quill_delta.dart +++ b/lib/models/quill_delta.dart @@ -51,8 +51,7 @@ class Operation { final Map? _attributes; Operation._(this.key, this.length, this.data, Map? attributes) - : - assert(_validKeys.contains(key), 'Invalid operation key "$key".'), + : assert(_validKeys.contains(key), 'Invalid operation key "$key".'), assert(() { if (key != Operation.insertKey) return true; return data is String ? data.length == length : length == 1; @@ -144,7 +143,8 @@ class Operation { } /// Returns `true` if this operation has attribute specified by [name]. - bool hasAttribute(String name) => isNotPlain && _attributes!.containsKey(name); + bool hasAttribute(String name) => + isNotPlain && _attributes!.containsKey(name); /// Returns `true` if [other] operation has the same attributes as this one. bool hasSameAttributes(Operation other) { @@ -154,8 +154,8 @@ class Operation { @override int get hashCode { if (_attributes != null && _attributes!.isNotEmpty) { - final attrsHash = - hashcode.hashObjects(_attributes!.entries.map((e) => hashcode.hash2(e.key, e.value))); + final attrsHash = hashcode.hashObjects( + _attributes!.entries.map((e) => hashcode.hash2(e.key, e.value))); return hashcode.hash3(key, value, attrsHash); } return hashcode.hash2(key, value); @@ -242,9 +242,7 @@ class Delta { int _modificationCount = 0; - Delta._(List operations) - : - _operations = operations; + Delta._(List operations) : _operations = operations; /// Creates new empty [Delta]. factory Delta() => Delta._([]); @@ -395,7 +393,8 @@ class Delta { /// Returns new operation or `null` if operations from [thisIter] and /// [otherIter] nullify each other. For instance, for the pair `insert('abc')` /// and `delete(3)` composition result would be empty string. - Operation? _composeOperation(DeltaIterator thisIter, DeltaIterator otherIter) { + Operation? _composeOperation( + DeltaIterator thisIter, DeltaIterator otherIter) { if (otherIter.isNextInsert) return otherIter.next(); if (thisIter.isNextDelete) return thisIter.next(); @@ -656,8 +655,8 @@ class DeltaIterator { _offset += actualLength; } final opData = op.isInsert && op.data is String - ? (op.data as String) - .substring(_currentOffset as int, _currentOffset + (actualLength as int)) + ? (op.data as String).substring( + _currentOffset as int, _currentOffset + (actualLength as int)) : op.data; final opIsNotEmpty = opData is String ? opData.isNotEmpty : true; // embeds are never empty diff --git a/lib/models/rules/insert.dart b/lib/models/rules/insert.dart index ea4f4925..61829972 100644 --- a/lib/models/rules/insert.dart +++ b/lib/models/rules/insert.dart @@ -341,7 +341,7 @@ class PreserveInlineStylesRule extends InsertRule { ..retain(index) ..insert(text, attributes.isEmpty ? null : attributes); Operation next = itr.next(); - + Map nextAttributes = next.attributes ?? const {}; if (!nextAttributes.containsKey(Attribute.link.key)) { diff --git a/lib/utils/hashcode.dart b/lib/utils/hashcode.dart index fe1e7985..38b51ce5 100644 --- a/lib/utils/hashcode.dart +++ b/lib/utils/hashcode.dart @@ -28,4 +28,4 @@ int _finish(int hash) { hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); hash = hash ^ (hash >> 11); return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); -} \ No newline at end of file +} diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index fbb9c7ff..2ea56e32 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -14,8 +14,7 @@ class QuillController extends ChangeNotifier { TextSelection selection; Style toggledStyle = Style(); - QuillController({required this.document, required this.selection}) - ; + QuillController({required this.document, required this.selection}); factory QuillController.basic() { return QuillController( @@ -85,8 +84,7 @@ class QuillController extends ChangeNotifier { print('document.replace failed: $e'); throw e; } - bool shouldRetainDelta = - toggledStyle.isNotEmpty && + bool shouldRetainDelta = toggledStyle.isNotEmpty && delta.isNotEmpty && delta.length <= 2 && delta.last.isInsert; @@ -137,7 +135,9 @@ class QuillController extends ChangeNotifier { } formatText(int index, int len, Attribute? attribute) { - if (len == 0 && attribute!.isInline && attribute.key != Attribute.link.key) { + if (len == 0 && + attribute!.isInline && + attribute.key != Attribute.link.key) { toggledStyle = toggledStyle.put(attribute); } @@ -164,16 +164,15 @@ class QuillController extends ChangeNotifier { if (delta.isNotEmpty) { document.compose(delta, source); } - - textSelection = selection.copyWith( - baseOffset: - delta.transformPosition(selection.baseOffset, force: false), - extentOffset: - delta.transformPosition(selection.extentOffset, force: false)); - if (selection != textSelection) { - _updateSelection(textSelection, source); - } - + + textSelection = selection.copyWith( + baseOffset: delta.transformPosition(selection.baseOffset, force: false), + extentOffset: + delta.transformPosition(selection.extentOffset, force: false)); + if (selection != textSelection) { + _updateSelection(textSelection, source); + } + notifyListeners(); } diff --git a/lib/widgets/cursor.dart b/lib/widgets/cursor.dart index 1450e4f9..d6305569 100644 --- a/lib/widgets/cursor.dart +++ b/lib/widgets/cursor.dart @@ -67,8 +67,7 @@ class CursorCont extends ChangeNotifier { required ValueNotifier show, required CursorStyle style, required TickerProvider tickerProvider, - }) : - show = show, + }) : show = show, _style = style, _blink = ValueNotifier(false), color = ValueNotifier(style.color) { diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 6402743b..7beb9f5c 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -9,8 +9,7 @@ class QuillStyles extends InheritedWidget { Key? key, required this.data, required Widget child, - }) : - super(key: key, child: child); + }) : super(key: key, child: child); @override bool updateShouldNotify(QuillStyles oldWidget) { diff --git a/lib/widgets/delegate.dart b/lib/widgets/delegate.dart index 0898c4f5..a8278246 100644 --- a/lib/widgets/delegate.dart +++ b/lib/widgets/delegate.dart @@ -21,8 +21,7 @@ class EditorTextSelectionGestureDetectorBuilder { final EditorTextSelectionGestureDetectorBuilderDelegate delegate; bool shouldShowSelectionToolbar = true; - EditorTextSelectionGestureDetectorBuilder(this.delegate) - ; + EditorTextSelectionGestureDetectorBuilder(this.delegate); EditorState? getEditor() { return delegate.getEditableTextKey().currentState; diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index a5faebf6..bc817470 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -181,8 +181,7 @@ class QuillEditor extends StatefulWidget { this.scrollPhysics, this.onLaunchUrl, this.embedBuilder = - kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder}) - ; + kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder}); factory QuillEditor.basic( {required QuillController controller, required bool readOnly}) { @@ -205,7 +204,8 @@ class QuillEditor extends StatefulWidget { class _QuillEditorState extends State implements EditorTextSelectionGestureDetectorBuilderDelegate { final GlobalKey _editorKey = GlobalKey(); - late EditorTextSelectionGestureDetectorBuilder _selectionGestureDetectorBuilder; + late EditorTextSelectionGestureDetectorBuilder + _selectionGestureDetectorBuilder; @override void initState() { @@ -420,7 +420,8 @@ class _QuillEditorSelectionGestureDetectorBuilder imageProvider: imageUrl.startsWith('http') ? NetworkImage(imageUrl) : isBase64(imageUrl) - ? Image.memory(base64.decode(imageUrl)) as ImageProvider? + ? Image.memory(base64.decode(imageUrl)) + as ImageProvider? : FileImage(io.File(imageUrl)), ), ), @@ -553,8 +554,7 @@ class RenderEditor extends RenderEditableContainerBox this._startHandleLayerLink, this._endHandleLayerLink, EdgeInsets floatingCursorAddedMargin) - : - super( + : super( children, document.root, textDirection, @@ -604,7 +604,6 @@ class RenderEditor extends RenderEditableContainerBox @override List getEndpointsForSelection( TextSelection textSelection) { - if (textSelection.isCollapsed) { RenderEditableBox child = childAtPosition(textSelection.extent); TextPosition localPosition = TextPosition( @@ -701,7 +700,7 @@ class RenderEditor extends RenderEditableContainerBox !focusingEmpty) { return; } - onSelectionChanged(nextSelection, cause); + onSelectionChanged(nextSelection, cause); } @override @@ -904,8 +903,7 @@ class RenderEditableContainerBox extends RenderBox RenderEditableContainerBox(List? children, this._container, this.textDirection, this._padding) - : - assert(_padding.isNonNegative) { + : assert(_padding.isNonNegative) { addAll(children); } @@ -1013,7 +1011,8 @@ class RenderEditableContainerBox extends RenderBox .deflate(_resolvedPadding!); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); - final EditableContainerParentData childParentData = child.parentData as EditableContainerParentData; + final EditableContainerParentData childParentData = + child.parentData as EditableContainerParentData; childParentData.offset = Offset(_resolvedPadding!.left, mainAxisExtent); mainAxisExtent += child.size.height; assert(child.parentData == childParentData); @@ -1030,7 +1029,8 @@ class RenderEditableContainerBox extends RenderBox var child = firstChild; while (child != null) { extent = math.max(extent, childSize(child)); - EditableContainerParentData childParentData = child.parentData as EditableContainerParentData; + EditableContainerParentData childParentData = + child.parentData as EditableContainerParentData; child = childParentData.nextSibling; } return extent; @@ -1041,7 +1041,8 @@ class RenderEditableContainerBox extends RenderBox var child = firstChild; while (child != null) { extent += childSize(child); - EditableContainerParentData childParentData = child.parentData as EditableContainerParentData; + EditableContainerParentData childParentData = + child.parentData as EditableContainerParentData; child = childParentData.nextSibling; } return extent; @@ -1075,8 +1076,8 @@ class RenderEditableContainerBox extends RenderBox double computeMinIntrinsicHeight(double width) { _resolvePadding(); return _getIntrinsicMainAxis((RenderBox child) { - double childWidth = - math.max(0.0, width - _resolvedPadding!.left + _resolvedPadding!.right); + double childWidth = math.max( + 0.0, width - _resolvedPadding!.left + _resolvedPadding!.right); return child.getMinIntrinsicHeight(childWidth) + _resolvedPadding!.top + _resolvedPadding!.bottom; @@ -1087,8 +1088,8 @@ class RenderEditableContainerBox extends RenderBox double computeMaxIntrinsicHeight(double width) { _resolvePadding(); return _getIntrinsicMainAxis((RenderBox child) { - final childWidth = - math.max(0.0, width - _resolvedPadding!.left + _resolvedPadding!.right); + final childWidth = math.max( + 0.0, width - _resolvedPadding!.left + _resolvedPadding!.right); return child.getMaxIntrinsicHeight(childWidth) + _resolvedPadding!.top + _resolvedPadding!.bottom; @@ -1102,4 +1103,3 @@ class RenderEditableContainerBox extends RenderBox _resolvedPadding!.top; } } - diff --git a/lib/widgets/keyboard_listener.dart b/lib/widgets/keyboard_listener.dart index 81c9b5db..485d1e19 100644 --- a/lib/widgets/keyboard_listener.dart +++ b/lib/widgets/keyboard_listener.dart @@ -58,8 +58,7 @@ class KeyboardListener { LogicalKeyboardKey.keyA: InputShortcut.SELECT_ALL, }; - KeyboardListener(this.onCursorMove, this.onShortcut, this.onDelete) - ; + KeyboardListener(this.onCursorMove, this.onShortcut, this.onDelete); bool handleRawKeyEvent(RawKeyEvent event) { if (event is! RawKeyDownEvent) { diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 5829e2ed..59231683 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -907,22 +907,22 @@ class RawEditorState extends EditorState _selectionOverlay?.hide(); _selectionOverlay = null; - _selectionOverlay = EditorTextSelectionOverlay( - textEditingValue, - false, - context, - widget, - _toolbarLayerLink, - _startHandleLayerLink, - _endHandleLayerLink, - getRenderEditor(), - widget.selectionCtrls, - this, - DragStartBehavior.start, - null, - _clipboardStatus); - _selectionOverlay!.handlesVisible = _shouldShowSelectionHandles(); - _selectionOverlay!.showHandles(); + _selectionOverlay = EditorTextSelectionOverlay( + textEditingValue, + false, + context, + widget, + _toolbarLayerLink, + _startHandleLayerLink, + _endHandleLayerLink, + getRenderEditor(), + widget.selectionCtrls, + this, + DragStartBehavior.start, + null, + _clipboardStatus); + _selectionOverlay!.handlesVisible = _shouldShowSelectionHandles(); + _selectionOverlay!.showHandles(); } } diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index ac6b4853..6a12559f 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -73,8 +73,7 @@ class EditableTextBlock extends StatelessWidget { this.contentPadding, this.embedBuilder, this.cursorCont, - this.indentLevelCounts) - ; + this.indentLevelCounts); @override Widget build(BuildContext context) { @@ -151,8 +150,8 @@ class EditableTextBlock extends StatelessWidget { if (attrs[Attribute.list.key] == Attribute.ul) { return _BulletPoint( - style: - defaultStyles!.paragraph!.style.copyWith(fontWeight: FontWeight.bold), + style: defaultStyles!.paragraph!.style + .copyWith(fontWeight: FontWeight.bold), width: 32, ); } @@ -261,8 +260,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox required Decoration decoration, ImageConfiguration configuration = ImageConfiguration.empty, EdgeInsets contentPadding = EdgeInsets.zero, - }) : - _decoration = decoration, + }) : _decoration = decoration, _configuration = configuration, _savedPadding = padding, _contentPadding = contentPadding, @@ -520,8 +518,7 @@ class _EditableBlock extends MultiChildRenderObjectWidget { _EditableBlock(this.block, this.textDirection, this.padding, this.decoration, this.contentPadding, List children) - : - super(children: children); + : super(children: children); EdgeInsets get _padding => EdgeInsets.only(top: padding.item1, bottom: padding.item2); diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index 5fccd888..821d19bb 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -54,10 +54,9 @@ class EditorTextSelectionOverlay { this.selectionDelegate, this.dragStartBehavior, this.onSelectionHandleTapped, - this.clipboardStatus) - { + this.clipboardStatus) { OverlayState overlay = Overlay.of(context, rootOverlay: true)!; - + _toolbarController = AnimationController( duration: Duration(milliseconds: 150), vsync: overlay); } @@ -106,8 +105,7 @@ class EditorTextSelectionOverlay { Widget _buildHandle( BuildContext context, _TextSelectionHandlePosition position) { if ((_selection.isCollapsed && - position == _TextSelectionHandlePosition.END) - ) { + position == _TextSelectionHandlePosition.END)) { return Container(); } return Visibility( @@ -162,8 +160,6 @@ class EditorTextSelectionOverlay { } Widget _buildToolbar(BuildContext context) { - - List endpoints = renderObject!.getEndpointsForSelection(_selection); @@ -486,8 +482,7 @@ class EditorTextSelectionGestureDetector extends StatefulWidget { this.onDragSelectionEnd, this.behavior, required this.child, - }) : - super(key: key); + }) : super(key: key); final GestureTapDownCallback? onTapDown; diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index b8d7ed23..7cc61b22 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -186,7 +186,7 @@ class ToggleStyleButton extends StatefulWidget { required this.icon, required this.controller, this.childBuilder = defaultToggleStyleButtonBuilder, - }) : super(key: key); + }) : super(key: key); @override _ToggleStyleButtonState createState() => _ToggleStyleButtonState(); @@ -270,8 +270,7 @@ class ToggleCheckListButton extends StatefulWidget { required this.controller, this.childBuilder = defaultToggleStyleButtonBuilder, required this.attribute, - }) : - super(key: key); + }) : super(key: key); @override _ToggleCheckListButtonState createState() => _ToggleCheckListButtonState(); @@ -355,7 +354,8 @@ Widget defaultToggleStyleButtonBuilder( ? theme.primaryIconTheme.color : theme.iconTheme.color : theme.disabledColor; - final fillColor = isToggled != null ? theme.toggleableActiveColor : theme.canvasColor; + final fillColor = + isToggled != null ? theme.toggleableActiveColor : theme.canvasColor; return QuillIconButton( highlightElevation: 0, hoverElevation: 0, @@ -426,8 +426,8 @@ class _SelectHeaderStyleButtonState extends State { } } -Widget _selectHeadingStyleButtonBuilder( - BuildContext context, Attribute? value, ValueChanged onSelected) { +Widget _selectHeadingStyleButtonBuilder(BuildContext context, Attribute? value, + ValueChanged onSelected) { final style = TextStyle(fontSize: 13); final Map _valueToText = { @@ -496,8 +496,7 @@ class ImageButton extends StatefulWidget { required this.controller, required this.imageSource, this.onImagePickCallback}) - : - super(key: key); + : super(key: key); @override _ImageButtonState createState() => _ImageButtonState(); @@ -602,8 +601,7 @@ class ColorButton extends StatefulWidget { required this.icon, required this.controller, required this.background}) - : - super(key: key); + : super(key: key); @override _ColorButtonState createState() => _ColorButtonState(); @@ -741,8 +739,7 @@ class HistoryButton extends StatefulWidget { required this.icon, required this.controller, required this.undo}) - : - super(key: key); + : super(key: key); @override _HistoryButtonState createState() => _HistoryButtonState(); @@ -814,8 +811,7 @@ class IndentButton extends StatefulWidget { required this.icon, required this.controller, required this.isIncrease}) - : - super(key: key); + : super(key: key); @override _IndentButtonState createState() => _IndentButtonState(); @@ -866,8 +862,7 @@ class ClearFormatButton extends StatefulWidget { final QuillController controller; ClearFormatButton({Key? key, required this.icon, required this.controller}) - : - super(key: key); + : super(key: key); @override _ClearFormatButtonState createState() => _ClearFormatButtonState(); @@ -1223,7 +1218,8 @@ class _QuillDropdownButtonState extends State> { void _showMenu() { final popupMenuTheme = PopupMenuTheme.of(context); final button = context.findRenderObject() as RenderBox; - final overlay = Overlay.of(context)!.context.findRenderObject() as RenderBox; + final overlay = + Overlay.of(context)!.context.findRenderObject() as RenderBox; final position = RelativeRect.fromRect( Rect.fromPoints( button.localToGlobal(Offset.zero, ancestor: overlay),