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

Added temporary hack to disable long-press for Superlist (Relates to #1547) #1569

Merged
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
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
Loading