@@ -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 ) !
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.
6173do {
6274 let view = makeEditor ( " draft a " )
0 commit comments