From 283f19458ecd7fa175ccbac28983eb5622a16488 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 25 Oct 2023 22:58:47 -0700 Subject: [PATCH] Added temporary hack to disable long-press for Superlist (Relates to #1547) --- .../document_gestures_touch_android.dart | 4 +++- .../document_gestures_touch_ios.dart | 4 +++- .../platforms/mobile_documents.dart | 12 ++++++++++ .../super_editor_android_selection_test.dart | 22 +++++++++++++++++++ .../super_editor_ios_selection_test.dart | 22 +++++++++++++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/super_editor/lib/src/default_editor/document_gestures_touch_android.dart b/super_editor/lib/src/default_editor/document_gestures_touch_android.dart index 2eb3c1d61c..2570f9f9fa 100644 --- a/super_editor/lib/src/default_editor/document_gestures_touch_android.dart +++ b/super_editor/lib/src/default_editor/document_gestures_touch_android.dart @@ -497,7 +497,9 @@ class _AndroidDocumentTouchInteractorState extends State _globalTapDownOffset = details.globalPosition; _tapDownLongPressTimer?.cancel(); - _tapDownLongPressTimer = Timer(kLongPressTimeout, _onLongPressDown); + if (!disableLongPressSelectionForSuperlist) { + _tapDownLongPressTimer = Timer(kLongPressTimeout, _onLongPressDown); + } // Stop the caret from blinking, in case this tap down turns into a long-press drag, // or a caret drag. diff --git a/super_editor/lib/src/infrastructure/platforms/mobile_documents.dart b/super_editor/lib/src/infrastructure/platforms/mobile_documents.dart index 8b9bb2cf13..40e15fa99e 100644 --- a/super_editor/lib/src/infrastructure/platforms/mobile_documents.dart +++ b/super_editor/lib/src/infrastructure/platforms/mobile_documents.dart @@ -4,6 +4,18 @@ import 'package:super_editor/src/infrastructure/_scrolling.dart'; import 'package:super_editor/src/infrastructure/document_gestures.dart'; import 'package:super_editor/src/infrastructure/documents/selection_leader_document_layer.dart'; +/// Global flag that disables long-press selection for Android and iOS, as a hack for Superlist, because +/// Superlist has a custom long-press behavior per-component. +/// +/// This is a hack and is expected to be replaced ASAP. Issue: https://github.com/superlistapp/super_editor/issues/1547 +/// +/// The underlying issue is that the document layout components have a gesture mode of "translucent", which +/// lets both the document component and the overall document gesture interactor both respond to the touch +/// event. As a result, if a user long-presses on a component to re-order it, that long-press also triggers +/// the long-press text selection behavior within the standard document interactor. +@Deprecated("Don't use this unless you're Superlist. This will be removed ASAP. See issue #1547.") +bool disableLongPressSelectionForSuperlist = false; + /// Controls the display and position of a magnifier and a floating toolbar. class MagnifierAndToolbarController with ChangeNotifier { /// Whether the magnifier should be displayed. diff --git a/super_editor/test/super_editor/mobile/super_editor_android_selection_test.dart b/super_editor/test/super_editor/mobile/super_editor_android_selection_test.dart index 1aa37831cd..cf12558edf 100644 --- a/super_editor/test/super_editor/mobile/super_editor_android_selection_test.dart +++ b/super_editor/test/super_editor/mobile/super_editor_android_selection_test.dart @@ -29,6 +29,28 @@ void main() { _expectHandlesAndToolbar(); }); + testWidgetsOnAndroid("does nothing with hack global property", (tester) async { + disableLongPressSelectionForSuperlist = true; + addTearDown(() => disableLongPressSelectionForSuperlist = false); + + await _pumpAppWithLongText(tester); + + // Long press down on the middle of "conse|ctetur" + final gesture = await tester.longPressDownInParagraph("1", 33); + await tester.pump(); + + // Ensure that there's no selection. + expect(SuperEditorInspector.findDocumentSelection(), isNull); + + // Release the long-press. + await gesture.up(); + await tester.pump(); + + // Ensure that only the caret was placed, rather than an expanded selection due + // to a long press. + expect(SuperEditorInspector.findDocumentSelection()!.isCollapsed, isTrue); + }); + testWidgetsOnAndroid("selects by word when dragging upstream", (tester) async { await _pumpAppWithLongText(tester); diff --git a/super_editor/test/super_editor/mobile/super_editor_ios_selection_test.dart b/super_editor/test/super_editor/mobile/super_editor_ios_selection_test.dart index d407a75c8a..4153b83298 100644 --- a/super_editor/test/super_editor/mobile/super_editor_ios_selection_test.dart +++ b/super_editor/test/super_editor/mobile/super_editor_ios_selection_test.dart @@ -28,6 +28,28 @@ void main() { _expectHandlesAndToolbar(); }); + testWidgetsOnIos("does nothing with hack global property", (tester) async { + disableLongPressSelectionForSuperlist = true; + addTearDown(() => disableLongPressSelectionForSuperlist = false); + + await _pumpAppWithLongText(tester); + + // Long press down on the middle of "conse|ctetur" + final gesture = await tester.longPressDownInParagraph("1", 33); + await tester.pump(); + + // Ensure that there's no selection. + expect(SuperEditorInspector.findDocumentSelection(), isNull); + + // Release the long-press. + await gesture.up(); + await tester.pump(); + + // Ensure that only the caret was placed, rather than an expanded selection due + // to a long press. + expect(SuperEditorInspector.findDocumentSelection()!.isCollapsed, isTrue); + }); + testWidgetsOnIos("over handle does nothing", (tester) async { await _pumpAppWithLongText(tester);