diff --git a/analysis_options.yaml b/analysis_options.yaml index b00ad5ad..5e1da9dc 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -15,6 +15,7 @@ linter: - avoid_redundant_argument_values - avoid_types_on_closure_parameters - avoid_void_async + - cascade_invocations - directives_ordering - omit_local_variable_types - prefer_const_constructors diff --git a/lib/models/documents/nodes/block.dart b/lib/models/documents/nodes/block.dart index 0919806f..5128f598 100644 --- a/lib/models/documents/nodes/block.dart +++ b/lib/models/documents/nodes/block.dart @@ -31,8 +31,9 @@ class Block extends Container { if (!block.isFirst && block.previous is Block && prev!.style == block.style) { - block.moveChildToNewParent(prev as Container?); - block.unlink(); + block + ..moveChildToNewParent(prev as Container?) + ..unlink(); block = prev as Block; } final next = block.next; diff --git a/lib/models/documents/nodes/leaf.dart b/lib/models/documents/nodes/leaf.dart index 88aeca6c..3d98060e 100644 --- a/lib/models/documents/nodes/leaf.dart +++ b/lib/models/documents/nodes/leaf.dart @@ -141,8 +141,7 @@ abstract class Leaf extends Node { assert(this is Text); final text = _value as String; _value = text.substring(0, index); - final split = Leaf(text.substring(index)); - split.applyStyle(style); + final split = Leaf(text.substring(index))..applyStyle(style); insertAfter(split); return split; } @@ -158,8 +157,7 @@ abstract class Leaf extends Node { Leaf _isolate(int index, int length) { assert( index >= 0 && index < this.length && (index + length <= this.length)); - final target = splitAt(index)!; - target.splitAt(length); + final target = splitAt(index)!..splitAt(length); return target; } } diff --git a/lib/models/documents/nodes/line.dart b/lib/models/documents/nodes/line.dart index 7dba241f..08ec39ee 100644 --- a/lib/models/documents/nodes/line.dart +++ b/lib/models/documents/nodes/line.dart @@ -173,14 +173,12 @@ class Line extends Container { _unwrap(); } else if (blockStyle != parentStyle) { _unwrap(); - final block = Block(); - block.applyAttribute(blockStyle); + final block = Block()..applyAttribute(blockStyle); _wrap(block); block.adjust(); } } else if (blockStyle.value != null) { - final block = Block(); - block.applyAttribute(blockStyle); + final block = Block()..applyAttribute(blockStyle); _wrap(block); block.adjust(); } @@ -234,8 +232,7 @@ class Line extends Container { final query = queryChild(index, false); while (!query.node!.isLast) { - final next = last as Leaf; - next.unlink(); + final next = (last as Leaf)..unlink(); line.addFirst(next); } final child = query.node as Leaf; diff --git a/lib/models/documents/nodes/node.dart b/lib/models/documents/nodes/node.dart index d46b4647..ddd1078c 100644 --- a/lib/models/documents/nodes/node.dart +++ b/lib/models/documents/nodes/node.dart @@ -32,9 +32,7 @@ abstract class Node extends LinkedListEntry { int get length; Node clone() { - final node = newInstance(); - node.applyStyle(style); - return node; + return newInstance()..applyStyle(style); } int getOffset() { diff --git a/lib/models/rules/delete.dart b/lib/models/rules/delete.dart index def2e8c7..e6682f94 100644 --- a/lib/models/rules/delete.dart +++ b/lib/models/rules/delete.dart @@ -34,8 +34,7 @@ class PreserveLineStyleOnMergeRule extends DeleteRule { @override Delta? applyRule(Delta document, int index, {int? len, Object? data, Attribute? attribute}) { - final itr = DeltaIterator(document); - itr.skip(index); + final itr = DeltaIterator(document)..skip(index); var op = itr.next(1); if (op.data != '\n') { return null; diff --git a/lib/models/rules/format.dart b/lib/models/rules/format.dart index 470ca200..be201925 100644 --- a/lib/models/rules/format.dart +++ b/lib/models/rules/format.dart @@ -27,8 +27,7 @@ class ResolveLineFormatRule extends FormatRule { } var delta = Delta()..retain(index); - final itr = DeltaIterator(document); - itr.skip(index); + final itr = DeltaIterator(document)..skip(index); Operation op; for (var cur = 0; cur < len! && itr.hasNext; cur += op.length!) { op = itr.next(len - cur); @@ -106,8 +105,7 @@ class ResolveInlineFormatRule extends FormatRule { } final delta = Delta()..retain(index); - final itr = DeltaIterator(document); - itr.skip(index); + final itr = DeltaIterator(document)..skip(index); Operation op; for (var cur = 0; cur < len! && itr.hasNext; cur += op.length!) { diff --git a/lib/models/rules/insert.dart b/lib/models/rules/insert.dart index 97f386d5..f7d029a4 100644 --- a/lib/models/rules/insert.dart +++ b/lib/models/rules/insert.dart @@ -66,8 +66,7 @@ class PreserveBlockStyleOnInsertRule extends InsertRule { return null; } - final itr = DeltaIterator(document); - itr.skip(index); + final itr = DeltaIterator(document)..skip(index); final nextNewLine = _getNextNewLine(itr); final lineStyle = @@ -101,8 +100,8 @@ class PreserveBlockStyleOnInsertRule extends InsertRule { } if (resetStyle != null) { - delta.retain(nextNewLine.item2!); delta + ..retain(nextNewLine.item2!) ..retain((nextNewLine.item1!.data as String).indexOf('\n')) ..retain(1, resetStyle); } @@ -172,8 +171,7 @@ class ResetLineFormatOnNewLineRule extends InsertRule { return null; } - final itr = DeltaIterator(document); - itr.skip(index); + final itr = DeltaIterator(document)..skip(index); final cur = itr.next(); if (cur.data is! String || !(cur.data as String).startsWith('\n')) { return null; diff --git a/lib/widgets/cursor.dart b/lib/widgets/cursor.dart index 8a22c7c2..6c9ce734 100644 --- a/lib/widgets/cursor.dart +++ b/lib/widgets/cursor.dart @@ -133,8 +133,9 @@ class CursorCont extends ChangeNotifier { _blinkOpacityCont.value = 0.0; if (style.opacityAnimates) { - _blinkOpacityCont.stop(); - _blinkOpacityCont.value = 0.0; + _blinkOpacityCont + ..stop() + ..value = 0.0; } } diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 1b92dece..b77b4673 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -982,8 +982,8 @@ class RenderEditableContainerBox extends RenderBox .deflate(_resolvedPadding!); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); - final childParentData = child.parentData as EditableContainerParentData; - childParentData.offset = Offset(_resolvedPadding!.left, mainAxisExtent); + final childParentData = (child.parentData as EditableContainerParentData) + ..offset = Offset(_resolvedPadding!.left, mainAxisExtent); mainAxisExtent += child.size.height; assert(child.parentData == childParentData); child = childParentData.nextSibling; diff --git a/lib/widgets/proxy.dart b/lib/widgets/proxy.dart index 71fc219d..ef763b9b 100644 --- a/lib/widgets/proxy.dart +++ b/lib/widgets/proxy.dart @@ -160,14 +160,15 @@ class RichTextProxy extends SingleChildRenderObjectWidget { @override void updateRenderObject( BuildContext context, covariant RenderParagraphProxy renderObject) { - renderObject.textStyle = textStyle; - renderObject.textAlign = textAlign; - renderObject.textDirection = textDirection; - renderObject.textScaleFactor = textScaleFactor; - renderObject.locale = locale; - renderObject.strutStyle = strutStyle; - renderObject.textWidthBasis = textWidthBasis; - renderObject.textHeightBehavior = textHeightBehavior; + renderObject + ..textStyle = textStyle + ..textAlign = textAlign + ..textDirection = textDirection + ..textScaleFactor = textScaleFactor + ..locale = locale + ..strutStyle = strutStyle + ..textWidthBasis = textWidthBasis + ..textHeightBehavior = textHeightBehavior; } } diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index fc07a110..2f076a20 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -906,8 +906,9 @@ class RawEditorState extends EditorState _cursorCont.startOrStopCursorTimerIfNeeded( _hasFocus, widget.controller.selection); if (hasConnection) { - _cursorCont.stopCursorTimer(resetCharTicks: false); - _cursorCont.startCursorTimer(); + _cursorCont + ..stopCursorTimer(resetCharTicks: false) + ..startCursorTimer(); } SchedulerBinding.instance!.addPostFrameCallback( @@ -1168,14 +1169,15 @@ class _Editor extends MultiChildRenderObjectWidget { @override void updateRenderObject( BuildContext context, covariant RenderEditor renderObject) { - renderObject.document = document; - renderObject.setContainer(document.root); - renderObject.textDirection = textDirection; - renderObject.setHasFocus(hasFocus); - renderObject.setSelection(selection); - renderObject.setStartHandleLayerLink(startHandleLayerLink); - renderObject.setEndHandleLayerLink(endHandleLayerLink); - renderObject.onSelectionChanged = onSelectionChanged; - renderObject.setPadding(padding); + renderObject + ..document = document + ..setContainer(document.root) + ..textDirection = textDirection + ..setHasFocus(hasFocus) + ..setSelection(selection) + ..setStartHandleLayerLink(startHandleLayerLink) + ..setEndHandleLayerLink(endHandleLayerLink) + ..onSelectionChanged = onSelectionChanged + ..setPadding(padding); } } diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index b9808fad..9cb40275 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -538,11 +538,12 @@ class _EditableBlock extends MultiChildRenderObjectWidget { @override void updateRenderObject( BuildContext context, covariant RenderEditableTextBlock renderObject) { - renderObject.setContainer(block); - renderObject.textDirection = textDirection; - renderObject.setPadding(_padding); - renderObject.decoration = decoration; - renderObject.contentPadding = _contentPadding; + renderObject + ..setContainer(block) + ..textDirection = textDirection + ..setPadding(_padding) + ..decoration = decoration + ..contentPadding = _contentPadding; } } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 99075411..8eff21c3 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -120,14 +120,13 @@ class TextLine extends StatelessWidget { final style = textNode.style; var res = const TextStyle(); - final m = { + { Attribute.bold.key: defaultStyles.bold, Attribute.italic.key: defaultStyles.italic, Attribute.link.key: defaultStyles.link, Attribute.underline.key: defaultStyles.underline, Attribute.strikeThrough.key: defaultStyles.strikeThrough, - }; - m.forEach((k, s) { + }.forEach((k, s) { if (style.values.any((v) => v.key == k)) { res = _merge(res, s!); } @@ -244,15 +243,16 @@ class EditableTextLine extends RenderObjectWidget { @override void updateRenderObject( BuildContext context, covariant RenderEditableTextLine renderObject) { - renderObject.setLine(line); - renderObject.setPadding(_getPadding()); - renderObject.setTextDirection(textDirection); - renderObject.setTextSelection(textSelection); - renderObject.setColor(color); - renderObject.setEnableInteractiveSelection(enableInteractiveSelection); - renderObject.hasFocus = hasFocus; - renderObject.setDevicePixelRatio(devicePixelRatio); - renderObject.setCursorCont(cursorCont); + renderObject + ..setLine(line) + ..setPadding(_getPadding()) + ..setTextDirection(textDirection) + ..setTextSelection(textSelection) + ..setColor(color) + ..setEnableInteractiveSelection(enableInteractiveSelection) + ..hasFocus = hasFocus + ..setDevicePixelRatio(devicePixelRatio) + ..setCursorCont(cursorCont); } EdgeInsetsGeometry _getPadding() { @@ -694,8 +694,7 @@ class RenderEditableTextLine extends RenderEditableBox { : _resolvedPadding!.right; _body!.layout(innerConstraints, parentUsesSize: true); - final bodyParentData = _body!.parentData as BoxParentData; - bodyParentData.offset = + (_body!.parentData as BoxParentData).offset = Offset(_resolvedPadding!.left, _resolvedPadding!.top); if (_leading != null) { @@ -704,8 +703,8 @@ class RenderEditableTextLine extends RenderEditableBox { maxWidth: indentWidth, maxHeight: _body!.size.height); _leading!.layout(leadingConstraints, parentUsesSize: true); - final parentData = _leading!.parentData as BoxParentData; - parentData.offset = Offset(0.0, _resolvedPadding!.top); + (_leading!.parentData as BoxParentData).offset = + Offset(0.0, _resolvedPadding!.top); } size = constraints.constrain(Size( diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index c113faeb..ff008742 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -155,9 +155,10 @@ class EditorTextSelectionOverlay { default: throw 'Invalid position'; } - selectionDelegate.textEditingValue = - value.copyWith(selection: newSelection, composing: TextRange.empty); - selectionDelegate.bringIntoView(textPosition); + selectionDelegate + ..textEditingValue = + value.copyWith(selection: newSelection, composing: TextRange.empty) + ..bringIntoView(textPosition); } Widget _buildToolbar(BuildContext context) {