This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Android Text Input] Make the editing state listenable and allow batch edits #21534
Merged
fluttergithubbot
merged 22 commits into
flutter-team-archive:master
from
LongCatIsLooong:textinputplugin-no-echoing
Nov 11, 2020
Merged
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
592f161
wip
LongCatIsLooong fd88233
add test
LongCatIsLooong 69f2ece
add test
LongCatIsLooong ce03d81
Merge remote-tracking branch 'upstream/master' into textinputplugin-n…
LongCatIsLooong 163685d
fix tests
LongCatIsLooong 73bbb6a
Merge remote-tracking branch 'upstream/master' into textinputplugin-n…
LongCatIsLooong 810d53a
update composing region from framework
LongCatIsLooong 7d9865c
implement updateCursorAnchorInfo and updateExtractedText
LongCatIsLooong a33db84
wip
LongCatIsLooong f6905d7
Merge remote-tracking branch 'upstream/master' into textinputplugin-n…
LongCatIsLooong 420568f
update
LongCatIsLooong e7085d5
format
LongCatIsLooong 3a0ba3b
code comments
LongCatIsLooong b392823
more comments
LongCatIsLooong 7af82b2
more tests
LongCatIsLooong b8858a0
do not change editing state in a listener callback
LongCatIsLooong 2ddda33
more warnings
LongCatIsLooong 874c9aa
remove redundant warning
LongCatIsLooong f53d1ff
Merge remote-tracking branch 'upstream/master' into textinputplugin-n…
LongCatIsLooong 3cf59fb
add missing license
LongCatIsLooong 5aa1561
review
LongCatIsLooong b7d48b9
format
LongCatIsLooong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,7 @@ class InputConnectionAdaptor extends BaseInputConnection { | |
| // Used to determine if Samsung-specific hacks should be applied. | ||
| private final boolean isSamsung; | ||
|
|
||
| private boolean mRepeatCheckNeeded = false; | ||
| private TextEditingValue mLastSentTextEditngValue; | ||
| private TextEditingValue mLastKnownTextEditingValue; | ||
| // Data class used to get and store the last-sent values via updateEditingState to | ||
| // the framework. These are then compared against to prevent redundant messages | ||
| // with the same data before any valid operations were made to the contents. | ||
|
|
@@ -144,7 +143,7 @@ private void updateEditingState() { | |
| // occurred to mark this as dirty. This prevents duplicate remote updates of | ||
| // the same data, which can break formatters that change the length of the | ||
| // contents. | ||
| if (mRepeatCheckNeeded && currentValue.equals(mLastSentTextEditngValue)) { | ||
| if (currentValue.equals(mLastKnownTextEditingValue)) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -163,17 +162,13 @@ private void updateEditingState() { | |
| currentValue.composingStart, | ||
| currentValue.composingEnd); | ||
|
|
||
| mRepeatCheckNeeded = true; | ||
| mLastSentTextEditngValue = currentValue; | ||
| mLastKnownTextEditingValue = currentValue; | ||
| } | ||
|
|
||
| // This should be called whenever a change could have been made to | ||
| // the value of mEditable, which will make any call of updateEditingState() | ||
| // ineligible for repeat checking as we do not want to skip sending real changes | ||
| // to the framework. | ||
| public void markDirty() { | ||
| // Disable updateEditngState's repeat-update check | ||
| 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() { | ||
| mLastKnownTextEditingValue = new TextEditingValue(mEditable); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -198,7 +193,6 @@ public boolean endBatchEdit() { | |
| @Override | ||
| public boolean commitText(CharSequence text, int newCursorPosition) { | ||
| boolean result = super.commitText(text, newCursorPosition); | ||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -207,21 +201,18 @@ public boolean deleteSurroundingText(int beforeLength, int afterLength) { | |
| if (Selection.getSelectionStart(mEditable) == -1) return true; | ||
|
|
||
| boolean result = super.deleteSurroundingText(beforeLength, afterLength); | ||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { | ||
| boolean result = super.deleteSurroundingTextInCodePoints(beforeLength, afterLength); | ||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean setComposingRegion(int start, int end) { | ||
| boolean result = super.setComposingRegion(start, end); | ||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -233,7 +224,6 @@ public boolean setComposingText(CharSequence text, int newCursorPosition) { | |
| } else { | ||
| result = super.setComposingText(text, newCursorPosition); | ||
| } | ||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -255,7 +245,6 @@ public boolean finishComposingText() { | |
| } | ||
| } | ||
|
|
||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -272,7 +261,6 @@ public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { | |
| @Override | ||
| public boolean clearMetaKeyStates(int states) { | ||
| boolean result = super.clearMetaKeyStates(states); | ||
| markDirty(); | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -300,7 +288,6 @@ private boolean isSamsung() { | |
| @Override | ||
| public boolean setSelection(int start, int end) { | ||
| boolean result = super.setSelection(start, end); | ||
| markDirty(); | ||
| updateEditingState(); | ||
| return result; | ||
| } | ||
|
|
@@ -323,7 +310,6 @@ private static int clampIndexToEditable(int index, Editable editable) { | |
|
|
||
| @Override | ||
| public boolean sendKeyEvent(KeyEvent event) { | ||
| markDirty(); | ||
| if (event.getAction() == KeyEvent.ACTION_DOWN) { | ||
| if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) { | ||
| int selStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable); | ||
|
|
@@ -427,7 +413,6 @@ public boolean sendKeyEvent(KeyEvent event) { | |
|
|
||
| @Override | ||
| public boolean performContextMenuAction(int id) { | ||
| markDirty(); | ||
| if (id == android.R.id.selectAll) { | ||
| setSelection(0, mEditable.length()); | ||
| return true; | ||
|
|
@@ -487,7 +472,6 @@ public boolean performPrivateCommand(String action, Bundle data) { | |
|
|
||
| @Override | ||
| public boolean performEditorAction(int actionCode) { | ||
| markDirty(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| switch (actionCode) { | ||
| case EditorInfo.IME_ACTION_NONE: | ||
| textInputChannel.newline(mClient); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.