refactor: remove unnecessary import, add some comment to function

pull/1979/head
n7484443j 9 months ago
parent 9319c03fbf
commit 7f7efbddc9
  1. 7
      lib/src/widgets/others/delegate.dart
  2. 224
      test/bug_fix_test.dart

@ -87,6 +87,10 @@ class EditorTextSelectionGestureDetectorBuilder {
bool shouldShowSelectionToolbar = true;
PointerDeviceKind? kind;
/// Check if the selection toolbar should show.
///
/// If mouse is used, the toolbar should only show when right click.
/// Else, it should show when the selection is enabled.
bool checkSelectionToolbarShouldShow({required bool isAdditionalAction}) {
if (kind != PointerDeviceKind.mouse) {
return shouldShowSelectionToolbar;
@ -320,8 +324,7 @@ class EditorTextSelectionGestureDetectorBuilder {
/// * [EditorTextSelectionGestureDetector.onDragSelectionUpdate],
/// which triggers this callback./lib/src/material/text_field.dart
@protected
void onDragSelectionUpdate(
//DragStartDetails startDetails,
void onDragSelectionUpdate(//DragStartDetails startDetails,
DragUpdateDetails updateDetails) {
renderEditor!.extendSelection(
updateDetails.globalPosition,

@ -1,5 +1,3 @@
import 'dart:ui';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
@ -10,51 +8,51 @@ void main() {
group('Bug fix', () {
group(
'1266 - QuillToolbar.basic() custom buttons do not have correct fill'
'color set', () {
'color set', () {
testWidgets('fillColor of custom buttons and builtin buttons match',
(tester) async {
const tooltip = 'custom button';
final controller = QuillController.basic();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: QuillSimpleToolbar(
configurations: QuillSimpleToolbarConfigurations(
controller: controller,
showRedo: false,
customButtons: const [
QuillToolbarCustomButtonOptions(
tooltip: tooltip,
)
],
(tester) async {
const tooltip = 'custom button';
final controller = QuillController.basic();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: QuillSimpleToolbar(
configurations: QuillSimpleToolbarConfigurations(
controller: controller,
showRedo: false,
customButtons: const [
QuillToolbarCustomButtonOptions(
tooltip: tooltip,
)
],
),
),
),
),
),
),
);
final builtinFinder = find.descendant(
of: find.byType(QuillToolbarHistoryButton),
matching: find.byType(QuillToolbarIconButton),
matchRoot: true,
);
expect(builtinFinder, findsOneWidget);
// final builtinButton =
// builtinFinder.evaluate().first.widget as QuillToolbarIconButton;
final customFinder = find.descendant(
of: find.byType(QuillToolbar),
matching: find.byWidgetPredicate((widget) =>
);
final builtinFinder = find.descendant(
of: find.byType(QuillToolbarHistoryButton),
matching: find.byType(QuillToolbarIconButton),
matchRoot: true,
);
expect(builtinFinder, findsOneWidget);
// final builtinButton =
// builtinFinder.evaluate().first.widget as QuillToolbarIconButton;
final customFinder = find.descendant(
of: find.byType(QuillToolbar),
matching: find.byWidgetPredicate((widget) =>
widget is QuillToolbarIconButton && widget.tooltip == tooltip),
matchRoot: true);
expect(customFinder, findsOneWidget);
// final customButton =
// customFinder.evaluate().first.widget as QuillToolbarIconButton;
matchRoot: true);
expect(customFinder, findsOneWidget);
// final customButton =
// customFinder.evaluate().first.widget as QuillToolbarIconButton;
// expect(customButton.fillColor, equals(builtinButton.fillColor));
});
// expect(customButton.fillColor, equals(builtinButton.fillColor));
});
});
group('1189 - The provided text position is not in the current node', () {
@ -77,41 +75,41 @@ void main() {
});
testWidgets('Refocus editor after controller clears document',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Column(
children: [editor],
),
),
);
await tester.quillEnterText(find.byType(QuillEditor), 'test\n');
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Column(
children: [editor],
),
),
);
await tester.quillEnterText(find.byType(QuillEditor), 'test\n');
editor.focusNode.unfocus();
await tester.pump();
controller.clear();
editor.focusNode.requestFocus();
await tester.pump();
expect(tester.takeException(), isNull);
});
editor.focusNode.unfocus();
await tester.pump();
controller.clear();
editor.focusNode.requestFocus();
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('Refocus editor after removing block attribute',
(tester) async {
await tester.pumpWidget(MaterialApp(
home: Column(
children: [editor],
),
));
await tester.quillEnterText(find.byType(QuillEditor), 'test\n');
controller.formatSelection(Attribute.ul);
editor.focusNode.unfocus();
await tester.pump();
controller.formatSelection(const ListAttribute(null));
editor.focusNode.requestFocus();
await tester.pump();
expect(tester.takeException(), isNull);
});
(tester) async {
await tester.pumpWidget(MaterialApp(
home: Column(
children: [editor],
),
));
await tester.quillEnterText(find.byType(QuillEditor), 'test\n');
controller.formatSelection(Attribute.ul);
editor.focusNode.unfocus();
await tester.pump();
controller.formatSelection(const ListAttribute(null));
editor.focusNode.requestFocus();
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('Tap checkbox in unfocused editor', (tester) async {
await tester.pumpWidget(
@ -146,46 +144,46 @@ void main() {
for (final device in [PointerDeviceKind.mouse, PointerDeviceKind.touch]) {
testWidgets(
'1742 - Disable context menu after selection for desktop platform $device',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: QuillEditor(
focusNode: FocusNode(),
scrollController: ScrollController(),
// ignore: avoid_redundant_argument_values
configurations: QuillEditorConfigurations(
controller: controller,
// ignore: avoid_redundant_argument_values
autoFocus: true,
expands: true,
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: QuillEditor(
focusNode: FocusNode(),
scrollController: ScrollController(),
// ignore: avoid_redundant_argument_values
configurations: QuillEditorConfigurations(
controller: controller,
// ignore: avoid_redundant_argument_values
autoFocus: true,
expands: true,
),
),
),
),
),
);
if (device == PointerDeviceKind.mouse) {
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
// Long press to show menu
await tester.longPress(find.byType(QuillEditor), kind: device);
await tester.pumpAndSettle();
// Verify custom widget not shows
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
await tester.tap(find.byType(QuillEditor),
buttons: kSecondaryButton, kind: device);
await tester.pumpAndSettle();
// Verify custom widget shows
expect(find.byType(AdaptiveTextSelectionToolbar), findsAny);
} else {
// Long press to show menu
await tester.longPress(find.byType(QuillEditor), kind: device);
await tester.pumpAndSettle();
// Verify custom widget shows
expect(find.byType(AdaptiveTextSelectionToolbar), findsAny);
}
});
);
if (device == PointerDeviceKind.mouse) {
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
// Long press to show menu
await tester.longPress(find.byType(QuillEditor), kind: device);
await tester.pumpAndSettle();
// Verify custom widget not shows
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
await tester.tap(find.byType(QuillEditor),
buttons: kSecondaryButton, kind: device);
await tester.pumpAndSettle();
// Verify custom widget shows
expect(find.byType(AdaptiveTextSelectionToolbar), findsAny);
} else {
// Long press to show menu
await tester.longPress(find.byType(QuillEditor), kind: device);
await tester.pumpAndSettle();
// Verify custom widget shows
expect(find.byType(AdaptiveTextSelectionToolbar), findsAny);
}
});
}
});
}

Loading…
Cancel
Save