Skip to content

Commit

Permalink
PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre committed Dec 23, 2024
1 parent 4b8dca1 commit c0a2452
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class SuperEditorIosControlsController {
_shouldShowToolbar.dispose();
}

/// {@template ios_use_selection_heuristics}
/// Whether to adjust the user's selection similar to the way iOS does.
///
/// For example: iOS doesn't let users tap directly on a text offset. Instead,
Expand All @@ -139,6 +140,7 @@ class SuperEditorIosControlsController {
/// When this property is `true`, iOS-style heuristics should be used. When
/// this value is `false`, the user's gestures should directly impact the
/// area they touched.
/// {@endtemplate}
final bool useIosSelectionHeuristics;

/// Color of the text selection drag handles on iOS.
Expand Down Expand Up @@ -908,15 +910,15 @@ class _IosDocumentTouchInteractorState extends State<IosDocumentTouchInteractor>
}

final extentRect = _docLayout.getRectForPosition(collapsedPosition)!;
final caretRect = Rect.fromLTRB(
final caretHitArea = Rect.fromLTRB(
extentRect.left - 24,
extentRect.top,
extentRect.right + 24,
extentRect.bottom,
);

final docOffset = _interactorOffsetToDocumentOffset(interactorOffset);
return caretRect.contains(docOffset);
return caretHitArea.contains(docOffset);
}

bool _isOverBaseHandle(Offset interactorOffset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ final _log = iosTextFieldLog;
///
/// Selection changes are made via the given [textController].
class IOSTextFieldTouchInteractor extends StatefulWidget {
/// {@macro ios_use_selection_heuristics}
@visibleForTesting
static bool useIosSelectionHeuristics = true;

const IOSTextFieldTouchInteractor({
Key? key,
required this.focusNode,
Expand All @@ -52,9 +56,6 @@ class IOSTextFieldTouchInteractor extends StatefulWidget {
required this.child,
}) : super(key: key);

@visibleForTesting
static bool useIosSelectionHeuristics = true;

/// [FocusNode] for the text field that contains this [IOSTextFieldInteractor].
///
/// [IOSTextFieldInteractor] only shows editing controls, and listens for drag
Expand Down
3 changes: 2 additions & 1 deletion super_editor/test/flutter_test_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Future<void> testExecutable(FutureOr<void> Function() testMain) async {
// Disable indeterminate animations
BlinkController.indeterminateAnimationsEnabled = false;

// Disable iOS selection heuristics.
// Disable iOS selection heuristics, i.e, place the caret at the exact
// tapped position instead of placing it at word boundaries.
IOSTextFieldTouchInteractor.useIosSelectionHeuristics = false;

Testing.isInTest = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void main() {
)),
);

// Tap at the caret.
// Tap on the caret.
await tester.tapInParagraph("1", 32);

// Ensure the selection was kept at "con|sectetur".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void main() {
const TextSelection.collapsed(offset: -1),
);

// Tap at "ips|um" to place the caret at the end of the word.
// Tap at "ips|um" to place the caret at the end of the word,
// because on iOS the caret is always placed at word boundaries.
await tester.placeCaretInSuperTextField(9);
await tester.pump(kDoubleTapTimeout);

Expand Down

0 comments on commit c0a2452

Please sign in to comment.