Skip to content

Commit 4ccd9d2

Browse files
committed
fix(mobile): send clears the iOS composer during IME composition
#17614 made the editor skip every controlled update while marked text exists, so the send-time draft clear was skipped and the composition commit later emitted the sent text back into the draft. Only the controlled document path may now replace a live composition; theme, font, layout, and icon repaints keep the unconditional deferral.
1 parent 5211acf commit 4ccd9d2

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

‎apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
660660
let previousSelection = sourceSelection()
661661
value = document.value
662662
requestedSelection = document.selection
663-
applyControlledDocument(force: tokensNeedRebuild)
663+
applyControlledDocument(force: tokensNeedRebuild, allowsReplacingComposition: true)
664664
applyRequestedSelection()
665665
cancelFocusingTapRestoreIfSelectionMoved(from: previousSelection)
666666
if tokensMatchCurrentValue() {
@@ -857,14 +857,29 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
857857
onComposerBlur()
858858
}
859859

860-
private func applyControlledDocument(force: Bool = false) {
861-
// Rebuilding the attributed string tears down an active IME composition.
862-
// Skip while marked text exists; committing the composition sends a new
863-
// value from JS, and that update rebuilds, keeping any skipped force.
860+
private func applyControlledDocument(
861+
force: Bool = false,
862+
allowsReplacingComposition: Bool = false
863+
) {
864+
// An identical value is an echo or a local repaint: defer until the
865+
// composition commits and replay any force. A different value is a
866+
// deliberate replacement, such as send clearing the draft, and must
867+
// win, or the commit later emits the sent text back into the draft.
864868
if textView.markedTextRange != nil {
865-
hasDeferredForcedRebuild = hasDeferredForcedRebuild || force
866-
updatePlaceholderVisibility()
867-
return
869+
if !allowsReplacingComposition || textView.serializedText() == value {
870+
hasDeferredForcedRebuild = hasDeferredForcedRebuild || force
871+
updatePlaceholderVisibility()
872+
return
873+
}
874+
isApplyingControlledValue = true
875+
textView.unmarkText()
876+
isApplyingControlledValue = false
877+
// A failed commit must not write attributed text under a live composition.
878+
guard textView.markedTextRange == nil else {
879+
hasDeferredForcedRebuild = true
880+
updatePlaceholderVisibility()
881+
return
882+
}
868883
}
869884
let shouldForce = force || hasDeferredForcedRebuild
870885
let currentSource = textView.serializedText()

0 commit comments

Comments
 (0)