Fix formatting

pull/87/head
Miller Adulu 4 years ago
parent b14c1dc9dc
commit d48abe8ea7
  1. 1
      lib/models/documents/attribute.dart
  2. 3
      lib/models/documents/nodes/embed.dart
  3. 3
      lib/models/documents/nodes/leaf.dart
  4. 4
      lib/models/documents/nodes/line.dart
  5. 4
      lib/models/documents/style.dart
  6. 21
      lib/models/quill_delta.dart
  7. 13
      lib/widgets/controller.dart
  8. 3
      lib/widgets/cursor.dart
  9. 3
      lib/widgets/default_styles.dart
  10. 3
      lib/widgets/delegate.dart
  11. 34
      lib/widgets/editor.dart
  12. 3
      lib/widgets/keyboard_listener.dart
  13. 13
      lib/widgets/text_block.dart
  14. 11
      lib/widgets/text_selection.dart
  15. 28
      lib/widgets/toolbar.dart

@ -1,4 +1,3 @@
import 'package:flutter_quill/utils/hashcode.dart' as hashcode;
enum AttributeScope {

@ -2,8 +2,7 @@ class Embeddable {
final String type;
final dynamic data;
Embeddable(this.type, this.data)
;
Embeddable(this.type, this.data);
Map<String, dynamic> toJson() {
Map<String, String> m = {type: data};

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

@ -36,7 +36,9 @@ class Line extends Container<Leaf?> {
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

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

@ -51,8 +51,7 @@ class Operation {
final Map<String, dynamic>? _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<Operation> operations)
:
_operations = operations;
Delta._(List<Operation> operations) : _operations = operations;
/// Creates new empty [Delta].
factory Delta() => Delta._(<Operation>[]);
@ -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

@ -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);
}
@ -166,8 +166,7 @@ class QuillController extends ChangeNotifier {
}
textSelection = selection.copyWith(
baseOffset:
delta.transformPosition(selection.baseOffset, force: false),
baseOffset: delta.transformPosition(selection.baseOffset, force: false),
extentOffset:
delta.transformPosition(selection.extentOffset, force: false));
if (selection != textSelection) {

@ -67,8 +67,7 @@ class CursorCont extends ChangeNotifier {
required ValueNotifier<bool> show,
required CursorStyle style,
required TickerProvider tickerProvider,
}) :
show = show,
}) : show = show,
_style = style,
_blink = ValueNotifier(false),
color = ValueNotifier(style.color) {

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

@ -21,8 +21,7 @@ class EditorTextSelectionGestureDetectorBuilder {
final EditorTextSelectionGestureDetectorBuilderDelegate delegate;
bool shouldShowSelectionToolbar = true;
EditorTextSelectionGestureDetectorBuilder(this.delegate)
;
EditorTextSelectionGestureDetectorBuilder(this.delegate);
EditorState? getEditor() {
return delegate.getEditableTextKey().currentState;

@ -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<QuillEditor>
implements EditorTextSelectionGestureDetectorBuilderDelegate {
final GlobalKey<EditorState> _editorKey = GlobalKey<EditorState>();
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<Object>?
? Image.memory(base64.decode(imageUrl))
as ImageProvider<Object>?
: 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<TextSelectionPoint> getEndpointsForSelection(
TextSelection textSelection) {
if (textSelection.isCollapsed) {
RenderEditableBox child = childAtPosition(textSelection.extent);
TextPosition localPosition = TextPosition(
@ -904,8 +903,7 @@ class RenderEditableContainerBox extends RenderBox
RenderEditableContainerBox(List<RenderEditableBox>? 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;
}
}

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

@ -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<Widget> children)
:
super(children: children);
: super(children: children);
EdgeInsets get _padding =>
EdgeInsets.only(top: padding.item1, bottom: padding.item2);

@ -54,8 +54,7 @@ class EditorTextSelectionOverlay {
this.selectionDelegate,
this.dragStartBehavior,
this.onSelectionHandleTapped,
this.clipboardStatus)
{
this.clipboardStatus) {
OverlayState overlay = Overlay.of(context, rootOverlay: true)!;
_toolbarController = AnimationController(
@ -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<TextSelectionPoint> 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;

@ -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<SelectHeaderStyleButton> {
}
}
Widget _selectHeadingStyleButtonBuilder(
BuildContext context, Attribute? value, ValueChanged<Attribute?> onSelected) {
Widget _selectHeadingStyleButtonBuilder(BuildContext context, Attribute? value,
ValueChanged<Attribute?> onSelected) {
final style = TextStyle(fontSize: 13);
final Map<Attribute, String> _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<T> extends State<QuillDropdownButton<T>> {
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),

Loading…
Cancel
Save