Skip to content

Commit

Permalink
Added temporary hack to disable long-press for Superlist (Relates to #…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll authored Oct 26, 2023
1 parent a7dd237 commit 867457d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ class _AndroidDocumentTouchInteractorState extends State<AndroidDocumentTouchInt

_globalTapDownOffset = details.globalPosition;
_tapDownLongPressTimer?.cancel();
_tapDownLongPressTimer = Timer(kLongPressTimeout, _onLongPressDown);
if (!disableLongPressSelectionForSuperlist) {
_tapDownLongPressTimer = Timer(kLongPressTimeout, _onLongPressDown);
}
}

// Runs when a tap down has lasted long enough to signify a long-press.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ class _IosDocumentTouchInteractorState extends State<IosDocumentTouchInteractor>

_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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 867457d

Please sign in to comment.