[floating_cursor_selection] a somewhat "design doc" for floating cursor feature (flutter/engine#42173)
This PR gives an overview of how floating cursor feature works (including the new floating cursor selection gesture, and the existing floating cursor move gesture). It can serve as the missing design doc. I put it in the engine rather than the framework, since all logics are in one place, and it's closer to the UIKit behavior that I want to cover. Thanks @moffatman for helping me understanding it. *List which issues are fixed by this PR. You must list at least one issue.* https://github.com/flutter/flutter/issues/30476 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -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:
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user