Skip to content

Commit

Permalink
Fix Dart Analysis issues (fleather-editor#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
amantoux authored Oct 28, 2022
1 parent 66d68c2 commit 1734f73
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 69 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/fleather.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ jobs:
working-directory: ./packages/parchment
run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
# - name: Parchment - Analyze project source
# working-directory: ./packages/parchment
# run: dart analyze
- name: Parchment - Analyze project source
working-directory: ./packages/parchment
run: dart analyze --fatal-infos

- name: Parchment - Run tests
working-directory: ./packages/parchment
Expand All @@ -51,10 +50,9 @@ jobs:
working-directory: ./packages/fleather
run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
# - name: Fleather - Analyze project source
# working-directory: ./packages/fleather
# run: dart analyze
- name: Fleather - Analyze project source
working-directory: ./packages/fleather
run: flutter analyze --fatal-infos

- name: Fleather - Run tests
working-directory: ./packages/fleather
Expand Down
6 changes: 0 additions & 6 deletions packages/fleather/lib/src/rendering/editable_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,6 @@ class RenderEditableContainerBox extends RenderBox
assert(size.isFinite);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
// properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection));
}

double _getIntrinsicCrossAxis(_ChildSizingFunction childSize) {
var extent = 0.0;
var child = firstChild;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:parchment/parchment.dart';

Expand Down
8 changes: 4 additions & 4 deletions packages/fleather/lib/src/rendering/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:parchment/parchment.dart';

import '../../fleather.dart';
import '../widgets/selection_utils.dart';
Expand Down Expand Up @@ -991,8 +990,7 @@ class RenderEditor extends RenderEditableContainerBox
}
}

class FleatherVerticalCaretMovementRun
extends BidirectionalIterator<TextPosition> {
class FleatherVerticalCaretMovementRun extends Iterator<TextPosition> {
FleatherVerticalCaretMovementRun._(
this._editor,
this._currentTextPosition,
Expand All @@ -1013,7 +1011,9 @@ class FleatherVerticalCaretMovementRun
return true;
}

@override
/// Move back to the previous element.
///
/// Returns true and updates [current] if successful.
bool movePrevious() {
_currentTextPosition = _editor.getTextPositionAbove(_currentTextPosition);
return true;
Expand Down
11 changes: 9 additions & 2 deletions packages/fleather/lib/src/widgets/cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ class CursorStyle {
}

@override
int get hashCode => hashValues(color, backgroundColor, width, height, radius,
offset, opacityAnimates, paintAboveText);
int get hashCode =>
color.hashCode ^
backgroundColor.hashCode ^
width.hashCode ^
height.hashCode ^
radius.hashCode ^
offset.hashCode ^
opacityAnimates.hashCode ^
paintAboveText.hashCode;
}

/// Controls cursor of an editable widget.
Expand Down
19 changes: 6 additions & 13 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class _FleatherEditorSelectionGestureDetectorBuilder
}
break;
case PointerDeviceKind.touch:
case PointerDeviceKind.trackpad:
case PointerDeviceKind.unknown:
// On macOS/iOS/iPadOS a touch tap places the cursor at the edge
// of the word.
Expand Down Expand Up @@ -836,7 +837,6 @@ class RawEditorState extends EditorState
void copySelection(SelectionChangedCause cause) {
final TextSelection selection = textEditingValue.selection;
final String text = textEditingValue.text;
assert(selection != null);
if (selection.isCollapsed) {
return;
}
Expand Down Expand Up @@ -875,7 +875,6 @@ class RawEditorState extends EditorState
}
final TextSelection selection = textEditingValue.selection;
final String text = textEditingValue.text;
assert(selection != null);
if (selection.isCollapsed) {
return;
}
Expand All @@ -894,7 +893,6 @@ class RawEditorState extends EditorState
return;
}
final TextSelection selection = textEditingValue.selection;
assert(selection != null);
if (!selection.isValid) {
return;
}
Expand Down Expand Up @@ -1587,13 +1585,6 @@ class _Editor extends MultiChildRenderObjectWidget {
renderObject.padding = padding;
renderObject.maxContentWidth = maxContentWidth;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
// TODO
// properties.add(EnumProperty<Axis>('direction', direction));
}
}

/// An interface for retriving the logical text boundary (left-closed-right-open)
Expand Down Expand Up @@ -1635,6 +1626,8 @@ abstract class _TextBoundary {

// ----------------------------- Text Boundaries -----------------------------

// TODO: Check whether to use it or remove it
// ignore: unused_element
class _CodeUnitBoundary extends _TextBoundary {
const _CodeUnitBoundary(this.textEditingValue);

Expand Down Expand Up @@ -1986,7 +1979,7 @@ class _UpdateTextSelectionAction<T extends DirectionalCaretMovementIntent>
final bool collapseSelection =
intent.collapseSelection || !state.widget.selectionEnabled;
// Collapse to the logical start/end.
TextSelection _collapse(TextSelection selection) {
TextSelection collapse(TextSelection selection) {
assert(selection.isValid);
assert(!selection.isCollapsed);
return selection.copyWith(
Expand All @@ -2000,7 +1993,7 @@ class _UpdateTextSelectionAction<T extends DirectionalCaretMovementIntent>
collapseSelection) {
return Actions.invoke(
context!,
UpdateSelectionIntent(state.textEditingValue, _collapse(selection),
UpdateSelectionIntent(state.textEditingValue, collapse(selection),
SelectionChangedCause.keyboard),
);
}
Expand All @@ -2017,7 +2010,7 @@ class _UpdateTextSelectionAction<T extends DirectionalCaretMovementIntent>
return Actions.invoke(
context!,
UpdateSelectionIntent(state.textEditingValue,
_collapse(textBoundarySelection), SelectionChangedCause.keyboard),
collapse(textBoundarySelection), SelectionChangedCause.keyboard),
);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/fleather/lib/src/widgets/editor_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LinkStyleButton extends StatefulWidget {
}) : super(key: key);

@override
_LinkStyleButtonState createState() => _LinkStyleButtonState();
State<LinkStyleButton> createState() => _LinkStyleButtonState();
}

class _LinkStyleButtonState extends State<LinkStyleButton> {
Expand Down Expand Up @@ -192,7 +192,7 @@ class ToggleStyleButton extends StatefulWidget {
}) : super(key: key);

@override
_ToggleStyleButtonState createState() => _ToggleStyleButtonState();
State<ToggleStyleButton> createState() => _ToggleStyleButtonState();
}

class _ToggleStyleButtonState extends State<ToggleStyleButton> {
Expand Down Expand Up @@ -298,7 +298,7 @@ class SelectHeadingStyleButton extends StatefulWidget {
: super(key: key);

@override
_SelectHeadingStyleButtonState createState() =>
State<SelectHeadingStyleButton> createState() =>
_SelectHeadingStyleButtonState();
}

Expand Down Expand Up @@ -408,7 +408,7 @@ class IndentationButton extends StatefulWidget {
: super(key: key);

@override
_IndentationButtonState createState() => _IndentationButtonState();
State<IndentationButton> createState() => _IndentationButtonState();
}

class _IndentationButtonState extends State<IndentationButton> {
Expand Down Expand Up @@ -683,7 +683,7 @@ class FleatherToolbar extends StatefulWidget implements PreferredSizeWidget {
}

@override
_FleatherToolbarState createState() => _FleatherToolbarState();
State<FleatherToolbar> createState() => _FleatherToolbarState();

@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
Expand Down Expand Up @@ -768,7 +768,7 @@ class FLDropdownButton<T> extends StatefulWidget {
}) : super(key: key);

@override
_FLDropdownButtonState<T> createState() => _FLDropdownButtonState<T>();
State<FLDropdownButton<T>> createState() => _FLDropdownButtonState<T>();
}

class _FLDropdownButtonState<T> extends State<FLDropdownButton<T>> {
Expand Down
13 changes: 0 additions & 13 deletions packages/fleather/lib/src/widgets/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@ class _TextSelectionHandleOverlay extends StatefulWidget {
class _TextSelectionHandleOverlayState
extends State<_TextSelectionHandleOverlay>
with SingleTickerProviderStateMixin {
late Offset _dragPosition;

late AnimationController _controller;

Animation<double> get _opacity => _controller.view;
Expand Down Expand Up @@ -456,17 +454,7 @@ class _TextSelectionHandleOverlayState
super.dispose();
}

void _handleDragStart(DragStartDetails details) {
final textPosition = widget.position == _TextSelectionHandlePosition.start
? widget.selection.base
: widget.selection.extent;
final lineHeight = widget.renderObject.preferredLineHeight(textPosition);
final Size handleSize = widget.selectionControls!.getHandleSize(lineHeight);
_dragPosition = details.globalPosition + Offset(0.0, -handleSize.height);
}

void _handleDragUpdate(DragUpdateDetails details) {
_dragPosition += details.delta;
final TextPosition position =
widget.renderObject.getPositionForOffset(details.globalPosition);
if (widget.selection.isCollapsed) {
Expand Down Expand Up @@ -578,7 +566,6 @@ class _TextSelectionHandleOverlayState
child: GestureDetector(
behavior: HitTestBehavior.translucent,
dragStartBehavior: widget.dragStartBehavior,
onPanStart: _handleDragStart,
onPanUpdate: _handleDragUpdate,
onTap: _handleTap,
child: Padding(
Expand Down
4 changes: 2 additions & 2 deletions packages/fleather/lib/src/widgets/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class FleatherThemeData {

final inlineCodeStyle = TextStyle(
fontSize: 14,
color: themeData.colorScheme.primaryVariant.withOpacity(0.8),
color: themeData.colorScheme.primaryContainer.withOpacity(0.8),
fontFamily: fontFamily,
);

Expand All @@ -163,7 +163,7 @@ class FleatherThemeData {
),
),
link: TextStyle(
color: themeData.colorScheme.primaryVariant,
color: themeData.colorScheme.primaryContainer,
decoration: TextDecoration.underline,
),
paragraph: TextBlockTheme(
Expand Down
1 change: 1 addition & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,6 @@ void prepareClipboard() {
if (message.method == 'Clipboard.hasStrings') {
return Future.value(<String, dynamic>{'value': true});
}
return null;
});
}
20 changes: 10 additions & 10 deletions packages/parchment/lib/src/convert/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _ParchmentMarkdownEncoder extends Converter<Delta, String> {
var currentInlineStyle = ParchmentStyle();
var currentBlockLines = [];

void _handleBlock(ParchmentAttribute<String>? blockStyle) {
void handleBlock(ParchmentAttribute<String>? blockStyle) {
if (currentBlockLines.isEmpty) {
return; // Empty block
}
Expand All @@ -60,19 +60,19 @@ class _ParchmentMarkdownEncoder extends Converter<Delta, String> {
buffer.writeln();
}

void _handleSpan(String text, Map<String, dynamic>? attributes) {
void handleSpan(String text, Map<String, dynamic>? attributes) {
final style = ParchmentStyle.fromJson(attributes);
currentInlineStyle =
_writeInline(lineBuffer, text, style, currentInlineStyle);
}

void _handleLine(Map<String, dynamic>? attributes) {
void handleLine(Map<String, dynamic>? attributes) {
final style = ParchmentStyle.fromJson(attributes);
final lineBlock = style.get(ParchmentAttribute.block);
if (lineBlock == currentBlockStyle) {
currentBlockLines.add(_writeLine(lineBuffer.toString(), style));
} else {
_handleBlock(currentBlockStyle);
handleBlock(currentBlockStyle);
currentBlockLines.clear();
currentBlockLines.add(_writeLine(lineBuffer.toString(), style));

Expand All @@ -86,30 +86,30 @@ class _ParchmentMarkdownEncoder extends Converter<Delta, String> {
final opText = op.data is String ? op.data as String : '';
final lf = opText.indexOf('\n');
if (lf == -1) {
_handleSpan(op.data as String, op.attributes);
handleSpan(op.data as String, op.attributes);
} else {
var span = StringBuffer();
for (var i = 0; i < opText.length; i++) {
if (opText.codeUnitAt(i) == 0x0A) {
if (span.isNotEmpty) {
// Write the span if it's not empty.
_handleSpan(span.toString(), op.attributes);
handleSpan(span.toString(), op.attributes);
}
// Close any open inline styles.
_handleSpan('', null);
_handleLine(op.attributes);
handleSpan('', null);
handleLine(op.attributes);
span.clear();
} else {
span.writeCharCode(opText.codeUnitAt(i));
}
}
// Remaining span
if (span.isNotEmpty) {
_handleSpan(span.toString(), op.attributes);
handleSpan(span.toString(), op.attributes);
}
}
}
_handleBlock(currentBlockStyle); // Close the last block
handleBlock(currentBlockStyle); // Close the last block
return buffer.toString();
}

Expand Down
8 changes: 4 additions & 4 deletions packages/parchment/lib/src/document/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'dart:math' as math;

import 'package:quill_delta/quill_delta.dart';

import 'embeds.dart';
import 'attributes.dart';
import 'block.dart';
import 'embeds.dart';
import 'leaf.dart';
import 'node.dart';

Expand Down Expand Up @@ -115,7 +115,7 @@ class LineNode extends ContainerNode<LeafNode>
var result = ParchmentStyle();
final excluded = <ParchmentAttribute>{};

void _handle(ParchmentStyle style) {
void handle(ParchmentStyle style) {
if (result.isEmpty) {
excluded.addAll(style.values);
} else {
Expand All @@ -137,7 +137,7 @@ class LineNode extends ContainerNode<LeafNode>
var pos = node.length - data.offset;
while (!node!.isLast && pos < local) {
node = node.next as LeafNode;
_handle(node.style);
handle(node.style);
pos += node.length;
}
}
Expand All @@ -151,7 +151,7 @@ class LineNode extends ContainerNode<LeafNode>
final remaining = length - local;
if (remaining > 0) {
final rest = nextLine!.collectStyle(0, remaining);
_handle(rest);
handle(rest);
}

return result;
Expand Down

0 comments on commit 1734f73

Please sign in to comment.