Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public void setComposingRange(int composingStart, int composingEnd) {
if (composingStart < 0 || composingStart >= composingEnd) {
BaseInputConnection.removeComposingSpans(this);
} else {
mDummyConnection.setComposingRegion(composingStart, composingEnd);
if (mDummyConnection != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make more sense to move the mDummyConnection initialization to before the setEditingState call in the constructor?

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 am not sure. Notice mDummyConnection is init as:

    Editable self = this;
    mDummyConnection =
        new BaseInputConnection(view, true) {
          @Override
          public Editable getEditable() {
            return self;
          }
        };

Where there is a self (indeed this). If we move it at the beginning of constructor, that getEditable can return a not-fully-initialized instance imho

Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly the dummy connection is a quirk to get access to the BaseInputConnection.setComposingRegion static method:
https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/inputmethod/BaseInputConnection.java;l=104-128;drc=master?q=BaseInputConnection

Since it's called after the super implementation, and all the dummy connection does is changing the current composing region, it should be fine to return the Editable I think (feel free to add a code comment there).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

mDummyConnection.setComposingRegion(composingStart, composingEnd);
} else {
Log.w(TAG, "setComposingRange skip since mDummyConnection is null");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
public void testConstructor() {
// When provided valid composing range, should not fail
new ListenableEditingState(
new TextInputChannel.TextEditState("hello", 1, 4, 1, 4),
new View(RuntimeEnvironment.application));
}

// -------- Start: Test BatchEditing -------
@Test
public void testBatchEditing() {
Expand Down