Cascade invocations

Use the cascading style when succesively invoking methods on the
same reference.
pull/145/head
Till Friebe 4 years ago
parent 0a136edb86
commit 78594aa266
  1. 1
      analysis_options.yaml
  2. 5
      lib/models/documents/nodes/block.dart
  3. 6
      lib/models/documents/nodes/leaf.dart
  4. 9
      lib/models/documents/nodes/line.dart
  5. 4
      lib/models/documents/nodes/node.dart
  6. 3
      lib/models/rules/delete.dart
  7. 6
      lib/models/rules/format.dart
  8. 8
      lib/models/rules/insert.dart
  9. 5
      lib/widgets/cursor.dart
  10. 4
      lib/widgets/editor.dart
  11. 17
      lib/widgets/proxy.dart
  12. 24
      lib/widgets/raw_editor.dart
  13. 11
      lib/widgets/text_block.dart
  14. 31
      lib/widgets/text_line.dart
  15. 7
      lib/widgets/text_selection.dart

@ -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

@ -31,8 +31,9 @@ class Block extends Container<Line?> {
if (!block.isFirst &&
block.previous is Block &&
prev!.style == block.style) {
block.moveChildToNewParent(prev as Container<Node?>?);
block.unlink();
block
..moveChildToNewParent(prev as Container<Node?>?)
..unlink();
block = prev as Block;
}
final next = block.next;

@ -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;
}
}

@ -173,14 +173,12 @@ class Line extends Container<Leaf?> {
_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<Leaf?> {
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;

@ -32,9 +32,7 @@ abstract class Node extends LinkedListEntry<Node> {
int get length;
Node clone() {
final node = newInstance();
node.applyStyle(style);
return node;
return newInstance()..applyStyle(style);
}
int getOffset() {

@ -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;

@ -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!) {

@ -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;

@ -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;
}
}

@ -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;

@ -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;
}
}

@ -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);
}
}

@ -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;
}
}

@ -120,14 +120,13 @@ class TextLine extends StatelessWidget {
final style = textNode.style;
var res = const TextStyle();
final m = <String, TextStyle?>{
<String, TextStyle?>{
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(

@ -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) {

Loading…
Cancel
Save