Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@hellohuanlin
Copy link
Contributor

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.

flutter/flutter#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.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

// 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, which indicates the beginning of
// the selection gesture. (This mechanism requires `closestPositionFromPoint` to be implemented, so
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setSelectedText doesn't necessarily mean the beginning of the selection gesture. It will be called during the selection gesture each time the finger moves enough to change the selection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I meant to say when setSelectedText is first time called, we can tell that user started the gesture. But there are also some nuances, such as the distance threshold of the gesture, as you said here. I think i can remove this part.

//
// Notice that 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 selection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say the selection is out of sync between framework and engine. It isn't modified in the framework during the move gesture until the end. So you can say the visual is out of sync with the selection state in both framework and engine.

// so exactly the same functions as the "move gesture" discussed above will be called. When the
// second finger is pressed, `setSelectedText` will be called, which indicates the beginning of
// the selection gesture. (This mechanism requires `closestPositionFromPoint` to be implemented, so
// that UIKit can determine the selected text range based on points.) When the selection is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that UIKit can determine which position in the text is the closest to any arbitrary screen point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "so that UIKit can determine which text position is the closest to any arbitrary screen point, hence determine the selected text range based on those points.".

It's definitely used for other features for sure, but I want this to be more specific to this particular feature.

@chinmaygarde
Copy link
Member

Are we intending to land this? @hellohuanlin, there is some feedback to incorporate.

@hellohuanlin
Copy link
Contributor Author

@chinmaygarde yep. will do.

@hellohuanlin hellohuanlin force-pushed the floating_cursor_selection_design_doc branch 3 times, most recently from 0d5601a to c3dc3e3 Compare June 8, 2023 17:52
@hellohuanlin hellohuanlin requested a review from moffatman June 8, 2023 21:15
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits thanks for adding this!

// 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 relative point to the framework, so that framework
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: relative to the initial position registered in beginFloatingCursorAtPoint or some such?

// 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 relative point to the framework, so that framework
// can animate the floating cursor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: animate -> correctly position?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just visually animate without actually updating the position.

// will be called. In all cases, we send the relative point to the framework, so that framework
// can animate the floating cursor.
//
// Notice that during the move gesture, the framework only animate the cursor visually. It's only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//
// Notice that 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after the gesture is complete, will the framework update the selection to the cursor's new position

I think this should probably be considered a bug? IIRC in a UIKit app the selection will actually be updated as you drag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd say it's "by design" - we did it on purpose. not saying whether this design is good or bad.

// 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, so that UIKit can determine which text position
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ... to be implemented to allow UIKit to translate the finger touch location displacement to the text range to select.

// 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember the "selection" gesture doesn't call {start, update, end}FloatingCursor for the 2nd finger and that was the reason the whole selection thing had to be implemented in the iOS embedder (I think we usually prefer implementing selection handling logic in the framework to avoid synchronization problems), maybe mention that if it isn't documented already?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one start,update,...,end for the whole sequence whether it's one or two fingers. We do continue to get update calls during the second finger movement, but no specific event when the second finger is pressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is something i should include. good that you remember it.

@hellohuanlin hellohuanlin force-pushed the floating_cursor_selection_design_doc branch from c3dc3e3 to ce62668 Compare June 12, 2023 17:25
@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 12, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 12, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jun 12, 2023

auto label is removed for flutter/engine, pr: 42173, due to - The status or check suite Linux mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 12, 2023
@auto-submit auto-submit bot merged commit 12def73 into flutter:main Jun 12, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 12, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants