Skip to content
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Merged
Changes from all 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 @@ -7,8 +7,13 @@
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputType;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextWatcher;
import android.text.method.ArrowKeyMovementMethod;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactContext;
Expand Down Expand Up @@ -79,6 +84,8 @@ public ReactAztecText(ThemedReactContext reactContext) {
// Needed on rotation and multiple Aztec instances to avoid losing the exact care position.
setFocusOnVisible(false);

forceCaretAtStartOnTakeFocus();

this.setAztecKeyListener(new ReactAztecText.OnAztecKeyListener() {
@Override
public boolean onEnterKey() {
Expand Down Expand Up @@ -107,6 +114,27 @@ public void onSelectionChanged(int selStart, int selEnd) {
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
}

private void forceCaretAtStartOnTakeFocus() {
// set a custom ArrowKeyMovementMethod: sets caret to the start of the text instead of the default (end of text)
// Fixes https://github.com/wordpress-mobile/gutenberg-mobile/issues/602
// onTakeFocus adapted from the Android source code at:
// https://android.googlesource.com/platform/frameworks/base/+/refs/heads/pie-release/core/java/android/text/method/ArrowKeyMovementMethod.java#316
setMovementMethod(new ArrowKeyMovementMethod() {
@Override
public void onTakeFocus(TextView view, Spannable text, int dir) {
if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
if (view.getLayout() == null) {
// This shouldn't be null, but do something sensible if it is.
Selection.setSelection(text, 0); // <-- setting caret to start of text
}
} else {
Selection.setSelection(text, text.length()); // <-- same as original Android implementation. Not sure if we should change this too
}
}
});

}

@Override
public void refreshText() {
super.refreshText();
Expand Down