refactor: remove unnecessary import, add some comment to function

pull/1979/head
n7484443j 10 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; bool shouldShowSelectionToolbar = true;
PointerDeviceKind? kind; 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}) { bool checkSelectionToolbarShouldShow({required bool isAdditionalAction}) {
if (kind != PointerDeviceKind.mouse) { if (kind != PointerDeviceKind.mouse) {
return shouldShowSelectionToolbar; return shouldShowSelectionToolbar;
@ -320,8 +324,7 @@ class EditorTextSelectionGestureDetectorBuilder {
/// * [EditorTextSelectionGestureDetector.onDragSelectionUpdate], /// * [EditorTextSelectionGestureDetector.onDragSelectionUpdate],
/// which triggers this callback./lib/src/material/text_field.dart /// which triggers this callback./lib/src/material/text_field.dart
@protected @protected
void onDragSelectionUpdate( void onDragSelectionUpdate(//DragStartDetails startDetails,
//DragStartDetails startDetails,
DragUpdateDetails updateDetails) { DragUpdateDetails updateDetails) {
renderEditor!.extendSelection( renderEditor!.extendSelection(
updateDetails.globalPosition, updateDetails.globalPosition,

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

Loading…
Cancel
Save