Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more gesture interceptors #757

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/services.dart';

import 'package:provider/provider.dart';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/selection/shared.dart';
import 'package:appflowy_editor/src/flutter/overlay.dart';
import 'package:appflowy_editor/src/service/selection/selection_gesture.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class DesktopSelectionServiceWidget extends StatefulWidget {
const DesktopSelectionServiceWidget({
Expand Down Expand Up @@ -235,6 +237,14 @@
}

void _onDoubleTapDown(TapDownDetails details) {
final canDoubleTap = _interceptors.every(
(interceptor) => interceptor.canDoubleTap?.call(details) ?? true,
);

if (!canDoubleTap) {
return updateSelection(null);

Check warning on line 245 in lib/src/editor/editor_component/service/selection/desktop_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/desktop_selection_service.dart#L245

Added line #L245 was not covered by tests
}

final offset = details.globalPosition;
final node = getNodeInOffset(offset);
final selection = node?.selectable?.getWordBoundaryInOffset(offset);
Expand Down Expand Up @@ -277,6 +287,13 @@
void _onPanStart(DragStartDetails details) {
clearSelection();

final canPanStart = _interceptors
.every((interceptor) => interceptor.canPanStart?.call(details) ?? true);

Check warning on line 291 in lib/src/editor/editor_component/service/selection/desktop_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/desktop_selection_service.dart#L290-L291

Added lines #L290 - L291 were not covered by tests

if (!canPanStart) {
return;
}

_panStartOffset = details.globalPosition.translate(-3.0, 0);
_panStartScrollDy = editorState.service.scrollService?.dy;

Expand All @@ -286,6 +303,14 @@
}

void _onPanUpdate(DragUpdateDetails details) {
final canPanUpdate = _interceptors.every(
(interceptor) => interceptor.canPanUpdate?.call(details) ?? true,

Check warning on line 307 in lib/src/editor/editor_component/service/selection/desktop_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/desktop_selection_service.dart#L306-L307

Added lines #L306 - L307 were not covered by tests
);

if (!canPanUpdate) {
return;
}

if (_panStartOffset == null ||
_panStartScrollDy == null ||
_panStartPosition == null) {
Expand Down Expand Up @@ -316,6 +341,13 @@
}

void _onPanEnd(DragEndDetails details) {
final canPanEnd = _interceptors
.every((interceptor) => interceptor.canPanEnd?.call(details) ?? true);

Check warning on line 345 in lib/src/editor/editor_component/service/selection/desktop_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/desktop_selection_service.dart#L344-L345

Added lines #L344 - L345 were not covered by tests

if (!canPanEnd) {
return;
}

_panStartPosition = null;

editorState.service.scrollService?.stopAutoScroll();
Expand Down
11 changes: 10 additions & 1 deletion lib/src/editor/editor_component/service/selection_service.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;

import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/location/position.dart';
import 'package:appflowy_editor/src/core/location/selection.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;

/// [AppFlowySelectionService] is responsible for processing
/// the [Selection] changes and updates.
Expand Down Expand Up @@ -87,9 +88,17 @@ class SelectionGestureInterceptor {
SelectionGestureInterceptor({
required this.key,
this.canTap,
this.canDoubleTap,
this.canPanStart,
this.canPanUpdate,
this.canPanEnd,
});

final String key;

bool Function(TapDownDetails details)? canTap;
bool Function(TapDownDetails details)? canDoubleTap;
bool Function(DragStartDetails details)? canPanStart;
bool Function(DragUpdateDetails details)? canPanUpdate;
bool Function(DragEndDetails details)? canPanEnd;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:io';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/services.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:appflowy_editor/appflowy_editor.dart';

import '../../../../infra/clipboard_test.dart';
import '../../../infra/testable_editor.dart';

Expand Down Expand Up @@ -40,12 +42,12 @@ void main() async {
(tester) async {
await _testHandleCopy(tester, Document.fromJson(data));
});
testWidgets(
'Presses Command + A in nested document and copy text nestednode',
(tester) async {
// TODO: fix this test
// await _testNestedNodeCopyPaste(tester, Document.fromJson(exampledoc));
});
// TODO: fix this test
// testWidgets(
// 'Presses Command + A in nested document and copy text nestednode',
// (tester) async {
// await _testNestedNodeCopyPaste(tester, Document.fromJson(exampledoc));
// });

testWidgets('update selection and execute cut command', (tester) async {
await _testCutHandle(tester, Document.fromJson(cutData));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/services.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:appflowy_editor/appflowy_editor.dart';

import '../../../infra/testable_editor.dart';

const _padding = 24.0;
Expand Down Expand Up @@ -103,8 +105,8 @@ void main() async {
});

// TODO(.): The purpose of this test is to catch addPostFrameCallback from
// calculateTextDirection but it doesn't catch it. Commenting the callback
// out doesn't make this test fail.
// calculateTextDirection but it doesn't catch it. Commenting the callback
// out doesn't make this test fail.
testWidgets(
"indent AUTO line under AUTO line changing the second line calculated direction",
(tester) async {
Expand Down
Loading