Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile] RichText - Fix backspacing and merging words (Android) #59831

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 @@ -312,15 +312,24 @@ export class RichText extends Component {
if ( this.shouldDropEventFromAztec( event, 'onChange' ) ) {
return;
}
const { eventCount, text, selectionStart, selectionEnd } =
event.nativeEvent;

// On Android backspacing after selection doesn't work as expected in some keyboards
// this makes sure to update the current selection the native AztecView has before merging.
if ( ! this.isIOS && selectionStart === 0 && selectionEnd === 0 ) {
this.selectionStart = selectionStart;
this.selectionEnd = selectionEnd;
this.props.onSelectionChange( selectionStart, selectionEnd );
}

const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
event.nativeEvent.text
);
const contentWithoutRootTag =
this.removeRootTagsProducedByAztec( text );
// On iOS, onChange can be triggered after selection changes, even though there are no content changes.
if ( contentWithoutRootTag === this.value?.toString() ) {
return;
}
this.lastEventCount = event.nativeEvent.eventCount;
this.lastEventCount = eventCount;
this.comesFromAztec = true;
this.firedAfterTextChanged = true; // The onChange event always fires after the fact.
this.onTextUpdate( event );
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-aztec/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
espressoVersion = '3.0.1'

// libs
aztecVersion = 'v2.1.2'
aztecVersion = '1077-fac06be6604f8cb24d34878c9961fa8503fd0e33'
wordpressUtilsVersion = '3.3.0'

// main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class AztecReactTextChangedEvent(
viewId: Int,
private val mText: String,
private val mEventCount: Int,
private val mMostRecentChar: Char?
private val mMostRecentChar: Char?,
private val mSelectionStart: Int,
private val mSelectionEnd: Int
) : Event<AztecReactTextChangedEvent>(viewId) {

override fun getEventName(): String = "topAztecChange"
Expand All @@ -30,5 +32,7 @@ class AztecReactTextChangedEvent(
if (mMostRecentChar != null) {
putInt("keyCode", mMostRecentChar.toInt())
}
putInt("selectionStart", mSelectionStart)
putInt("selectionEnd", mSelectionEnd)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,9 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
mEditText.getId(),
mEditText.toHtml(mEditText.getText(), false),
currentEventCount,
singleCharacterHasBeenAdded ? s.charAt(start + before) : null));
singleCharacterHasBeenAdded ? s.charAt(start + before) : null,
mEditText.getSelectionStart(),
mEditText.getSelectionStart()));

mEventDispatcher.dispatchEvent(
new ReactTextInputEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public ReactAztecText(ThemedReactContext reactContext) {

setGutenbergMode(true);

removeEndOfBufferMarkerAdder();

// don't auto-focus when Aztec becomes visible.
// Needed on rotation and multiple Aztec instances to avoid losing the exact care position.
setFocusOnVisible(false);
Expand Down
Loading