diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 4af9ac6ec8..2463a17f78 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -1836,6 +1836,34 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, return [FlutterTextRange rangeWithNSRange:fml::RangeForCharacterAtIndex(self.text, currentIndex)]; } +// Overall logic for floating cursor's "move" gesture and "selection" gesture: +// +// Floating cursor's "move" gesture takes 1 finger to force press the space bar, and then move the +// cursor. The process starts with `beginFloatingCursorAtPoint`. When the finger is moved, +// `updateFloatingCursorAtPoint` will be called. When the finger is released, `endFloatingCursor` +// will be called. In all cases, we send the point (relative to the initial point registered in +// beginFloatingCursorAtPoint) to the framework, so that framework can animate the floating cursor. +// +// During the move gesture, the framework only animate the cursor visually. It's only +// after the gesture is complete, will the framework update the selection to the cursor's +// new position (with zero selection length). This means during the animation, the visual effect +// of the cursor is temporarily out of sync with the selection state in both framework and engine. +// But it will be in sync again after the animation is complete. +// +// Floating cursor's "selection" gesture also starts with 1 finger to force press the space bar, +// so exactly the same functions as the "move gesture" discussed above will be called. When the +// second finger is pressed, `setSelectedText` will be called. This mechanism requires +// `closestPositionFromPoint` to be implemented, to allow UIKit to translate the finger touch +// location displacement to the text range to select. When the selection is completed +// (i.e. when both of the 2 fingers are released), similar to "move" gesture, +// the `endFloatingCursor` will be called. +// +// When the 2nd finger is pressed, it does not trigger another startFloatingCursor call. So +// floating cursor move/selection logic has to be implemented in iOS embedder rather than +// just the framework side. +// +// Whenever a selection is updated, the engine sends the new selection to the framework. So unlike +// the move gesture, the selections in the framework and the engine are always kept in sync. - (void)beginFloatingCursorAtPoint:(CGPoint)point { // For "beginFloatingCursorAtPoint" and "updateFloatingCursorAtPoint", "point" is roughly: //