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

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Oct 1, 2020

Description

Make the Editable held by both the input connection and the text input plugin listenable and allows for batch edits. I might have reinvented the wheel since there're already mechanisms like TextWatcher and SpanWatcher, but they don't seem to account for batch editing.

Most of the time when the editing state changes we need to notify the input method manager or the autofill manager. They do not care where each change comes from (framework or input method or autofill), nor do they directly modify the current editing state.

Now TextInputPlugin and InputConnectionAdaptor both listen to the shared ListenableEditingState:

  • TextInputPlugin sends text editing state update to the framework when a change is detected, also it notifies the autofill manager of text changes.
  • InputConnectionAdaptor sends updates to the input method manager when the editing state is changed.

Related PR

Fixes: flutter/flutter#69111
flutter/flutter#66864
#20160

Tests

I added the following tests:

setTextInputEditingState_doesNotInvokeUpdateEditingState
inputConnectionAdaptor_skipCallsAfterEditingValueUpdateFromFramework

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

mRepeatCheckNeeded = false;
// Called when the current text editing state held by the text input plugin is overwritten by a
// newly received value from the framework.
public void didUpdateEditingValue() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The android text input plugin doesn't seem to completely overwrite the input state with the newly received value, the composing range is ignored. If the text is composing and the user replaces the entire string with something else, would that put the input method in a broken state?

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried it out? Ignoring the composing region definitely seems incorrect. If there's no visible bug, maybe it's fixing itself when subsequent edits happen.

Copy link
Contributor Author

@LongCatIsLooong LongCatIsLooong Oct 13, 2020

Choose a reason for hiding this comment

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

I tried a 3rd party japanese IME that uses composing region, it's not working in flutter apps (not composing at all). I'll see if there's an easy fix.

update it seems the Japanese input bug fixed itself.

@LongCatIsLooong LongCatIsLooong changed the title [Android Text Input] G [Android Text Input] Further reduce updates sent to the framework Oct 1, 2020
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 as long as the tests pass. There is one failing now but I think it's just a problem with a test.

Thanks for jumping on all of these refactors, it's going to be a lot cleaner.

mRepeatCheckNeeded = false;
// Called when the current text editing state held by the text input plugin is overwritten by a
// newly received value from the framework.
public void didUpdateEditingValue() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried it out? Ignoring the composing region definitely seems incorrect. If there's no visible bug, maybe it's fixing itself when subsequent edits happen.


@Override
public boolean performEditorAction(int actionCode) {
markDirty();
Copy link
Contributor

Choose a reason for hiding this comment

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

It's great seeing all these markDirty's going away. This seems so much simpler.

@chinmaygarde
Copy link
Member

I don't think the failure is a flake. Can we fix the presubmit and land this?

@LongCatIsLooong LongCatIsLooong force-pushed the textinputplugin-no-echoing branch from ca21217 to 0f1e22f Compare October 12, 2020 22:25
@LongCatIsLooong LongCatIsLooong force-pushed the textinputplugin-no-echoing branch from 0f1e22f to 163685d Compare October 12, 2020 22:26
@chinmaygarde
Copy link
Member

@LongCatIsLooong: Can you tell if the failure is a flake? And, if not, land this patch?

@LongCatIsLooong
Copy link
Contributor Author

The failure doesn't look related. There's still something in the PR I'm trying to fix. Turning this into a draft.

@LongCatIsLooong LongCatIsLooong marked this pull request as draft October 15, 2020 23:00
@LongCatIsLooong LongCatIsLooong force-pushed the textinputplugin-no-echoing branch from 55d4578 to 0339d06 Compare October 29, 2020 06:24
@LongCatIsLooong LongCatIsLooong force-pushed the textinputplugin-no-echoing branch from 0339d06 to f6905d7 Compare October 29, 2020 06:33
@LongCatIsLooong
Copy link
Contributor Author

@justinmc @GaryQian FYI the test device came in this past Saturday (SM-T510). I managed to repro the Samsung issue on Flutter 1.12.13 hotfix 8, but not on upstream/master or this branch.

}
}

public final int getSelecionStart() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo, did you mean getSelection?

return Selection.getSelectionStart(this);
}

public final int getSelecionEnd() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, getSelection

@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
if (Selection.getSelectionStart(mEditable) == -1) return true;
if (mEditable.getSelecionStart() == -1) {
Copy link
Contributor

@GaryQian GaryQian Nov 10, 2020

Choose a reason for hiding this comment

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

*getSelectionStart


private BaseInputConnection mDummyConnection;

// The View is only use for creating a dummy BaseInputConnection for setComposingRegion. The View
Copy link
Contributor

Choose a reason for hiding this comment

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

is only used

}
if (mBatchEditNestDepth == 1 && !mListeners.isEmpty()) {
mTextWhenBeginBatchEdit = toString();
mSelectionStartWhenBeginBatchEdit = getSelecionStart();
Copy link
Contributor

Choose a reason for hiding this comment

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

getSelection

boolean textChanged, boolean selectionChanged, boolean composingRegionChanged);
}

private static final String TAG = "flutter";
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to use a tag specific to the class name in some cases, but (don't quote me on this) the tool may filter for flutter explicitly, so you should probably verify the message is visible when you want it to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated all 3 classes to use their class names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I change the level to Log.v it doesn't show up even if I change the TAG to "flutter" and use flutter run -v.

view, inputTarget.id, textInputChannel, keyProcessor, mEditable, outAttrs);
outAttrs.initialSelStart = Selection.getSelectionStart(mEditable);
outAttrs.initialSelEnd = Selection.getSelectionEnd(mEditable);
outAttrs.initialSelStart = mEditable.getSelecionStart();
Copy link
Contributor

Choose a reason for hiding this comment

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

getSelectionStart and getSelectionEnd

// ### Keep the AFM updated
//
// The autofill session connected to The AFM keeps a copy of the current state for each reported
// field in "AutofillVirtualStructure"(instead of holding a reference to those fields), so the AFM
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, space between " and (

Copy link
Contributor

@GaryQian GaryQian 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 a few nits

@LongCatIsLooong LongCatIsLooong added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 11, 2020
@fluttergithubbot fluttergithubbot merged commit 81f219c into flutter:master Nov 11, 2020
@LongCatIsLooong LongCatIsLooong deleted the textinputplugin-no-echoing branch November 11, 2020 03:21
LongCatIsLooong added a commit that referenced this pull request Nov 11, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 11, 2020
fluttergithubbot pushed a commit to flutter/flutter that referenced this pull request Nov 11, 2020
fluttergithubbot pushed a commit that referenced this pull request Nov 12, 2020
LongCatIsLooong added a commit to LongCatIsLooong/engine that referenced this pull request Nov 12, 2020
fluttergithubbot pushed a commit that referenced this pull request Nov 12, 2020
chaselatta pushed a commit to chaselatta/engine that referenced this pull request Nov 30, 2020
chaselatta pushed a commit to chaselatta/engine that referenced this pull request Nov 30, 2020
chaselatta pushed a commit to chaselatta/engine that referenced this pull request Nov 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects: text input cla: yes platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoFill unexpected behavior; TextInput.finishAutofillContext() doing nothing; Cannot save user input

6 participants