Skip to content

Commit d95da69

Browse files
committed
fix(mobile): apply composer resets that resemble native echoes
1 parent 14609bf commit d95da69

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
663663
nativeEventCount = document.mostRecentEventCount
664664
endComposition()
665665
}
666-
if document.isNativeEcho && textView.serializedText() != document.value {
666+
if document.isNativeEcho && !isReset && textView.serializedText() != document.value {
667667
return
668668
}
669669
if tokensJson != document.tokensJson {

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ extension T3ComposerEditorView {
1212
var text: String { textView.serializedText() }
1313
}
1414

15-
func document(_ value: String, revision: Int, resetGeneration: Int = 0) -> String {
15+
func document(_ value: String, revision: Int, resetGeneration: Int = 0, isNativeEcho: Bool = false) -> String {
1616
let payload: [String: Any] = [
1717
"value": value,
1818
"selection": NSNull(),
1919
"tokensJson": "[]",
2020
"mostRecentEventCount": revision,
21-
"isNativeEcho": false,
21+
"isNativeEcho": isNativeEcho,
2222
"resetGeneration": resetGeneration,
2323
]
2424
return String(data: try! JSONSerialization.data(withJSONObject: payload), encoding: .utf8)!
@@ -57,6 +57,18 @@ do {
5757
check(typed?["eventCount"] as? Int == 1, "Typing after the clear must follow the parent's revision")
5858
}
5959

60+
// An attachment-only send can reset an empty JS draft before a native keystroke is delivered.
61+
do {
62+
let view = makeEditor("")
63+
view.editor.insertText("x")
64+
view.setControlledDocumentJson(document("", revision: 0, resetGeneration: 1, isNativeEcho: true))
65+
check(view.text == "", "An echo-marked reset retained an undelivered keystroke: \(view.text)")
66+
view.editor.insertText("n")
67+
check(view.text == "n", "Typing after an echo-marked reset restored the previous keystroke")
68+
view.setControlledDocumentJson(document("", revision: 1, resetGeneration: 1, isNativeEcho: true))
69+
check(view.text == "n", "An ordinary mismatched echo overwrote newer native typing")
70+
}
71+
6072
// Moving the editor to another draft can lower the parent's reset generation; that payload stays ordinary.
6173
do {
6274
let view = makeEditor("draft a")

0 commit comments

Comments
 (0)