Skip to content

Conversation

@xu-baolin
Copy link
Member

@xu-baolin xu-baolin commented Aug 2, 2022

Fixes #108673
Fixes #84849

Issue 1 - Tap the word the handler appear randomly

1, Tap on the middle of 'Hello'
2, Local value update to

TextEditingValue(text:Hello World├, selection: TextSelection.collapsed(offset: 2, affinity: TextAffinity.upstream, isDirectional: false), composing: TextRange(start: -1, end: -1))

3, Send the new local value to remote, and then, the auto correction will update the composing back to framework

TextEditingValue(text:Hello World├, selection: TextSelection.collapsed(offset: 2, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 0, end: 2))

But the affinity will mutate randomly. I'm not sure if this is a problem with the engine, but I understand that in this scenario, affinity is meaningless.

If the affinity was mutate, the handle will be hide by _TextFieldState._handleSelectionChanged because the cause is keyboard.

Issue 2 - The handler can not drag to a new word

hideToolbar();
_currentPromptRectRange = null;

This is because we remove the handler overlay during drag because the engine update the composing during drag.

I found that we can remove the line, the handler's visibility will be updated by _TextFieldState._handleSelectionChanged CC @LongCatIsLooong

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Aug 2, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know this a little hack.
If we can figure out why the engine change the affinity maybe we have a better solution.
CC @LongCatIsLooong

Copy link
Contributor

Choose a reason for hiding this comment

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

The engine doesn't know/care about text affinity I believe. It always sets it to downstream.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have correct the value when receive the remote value. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you double check deleting this is safety? @LongCatIsLooong THX : )

Copy link
Contributor

Choose a reason for hiding this comment

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

In UIKit/Android apps, the text edit menu should go away once the user starts typing. Would this change that behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add a test to cover this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah _handleSelectionChanged is called in _formatAndSave too, that seems to be a messy callpath. Do you mind adding a comment to explain why we're not hiding the handles here (or link the issue)?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@xu-baolin
Copy link
Member Author

@LongCatIsLooong @justinmc Hi, guys, I think this is ready for review :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you still want to revert the affinity change if the user actually typed something?

Copy link
Member Author

Choose a reason for hiding this comment

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

As you point out that the input server never know the actually affinity and can not change the affinity by key board.
Currently we can only change the affinity by tap the text string and change the selection.
Additional, the affinity is only valid when line breaks cause by render wrapping, not explicit newline characters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry I misspoke, the engine doesn't care but the framework does (for rendering the caret at the right place).

As far as I can tell on iOS/Android when the user types using a virtual/hardware keyboard the affinity is always set to TextAffinity.downstream. TextAffinity.upstream is only used when the selection is change by certain gestures when the caret position is located at a soft-wrap line boundary, or bidi boundary. For example when the text field needs to show

aa|
bb

instead of

aa
|bb

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely correct, so we can override the affinity from engine, right?
Otherwise, the only affinity change will trigger selection change and dismiss the handler by mistake.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Aug 12, 2022

Choose a reason for hiding this comment

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

Say the line can only accommodate 2 characters, and the text editing state was initially
(text: 'a', textSelection.collapsed(1, affinity: upstream)), when the user types another a the affinity should be changed to downstream, so the framework knows the caret should be rendered at the start of line 2?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you explain why? The documentation says that affinity only makes sense when there is ambiguity in the visual location, and is used to paint the caret. Am I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

When the user types something, or changes the selection using a keyboard, the caret typically shouldn't be painted using the upstream affinity. In other words it should be

aa
|bb

instead of

aa|
bb

Copy link
Member Author

@xu-baolin xu-baolin Aug 15, 2022

Choose a reason for hiding this comment

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

I almost understand what you mean.
Another case, if the aa| is composed, and I wanna to type aaa| with composed, it should be painted using upstream affinity?

Copy link
Contributor

Choose a reason for hiding this comment

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

That I'm not sure. On Android it's behaving like it's upstream. But I vaguely remember there's no cursor affinity on Android.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

In UIKit/Android apps, the text edit menu should go away once the user starts typing. Would this change that behavior?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I was thinking this might have needed a tricky engine fix, I'm happy if that's not true.

Can you check if this fixes/improves #84849?

@xu-baolin
Copy link
Member Author

Can you check if this fixes/improves #84849?

Yes, this indeed fixes #84849 too.

@alexmercerind
Copy link

Can you check if this fixes/improves #84849?

Yes, this indeed fixes #84849 too.

Thanks a lot for your work!

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks again!

I tried running this locally and it does indeed appear to fix both of those issues!

value.selection.affinity != _value.selection.affinity) {
return true;
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you get rid of the if and just return the condition directly?

@xu-baolin xu-baolin added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 16, 2022
@auto-submit auto-submit bot merged commit 44f87da into flutter:master Aug 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text selection handler disappear when dragged to new words Input connection reinitiated when handles are dragged

4 participants