@@ -71,6 +71,7 @@ @interface AgentDeviceRunnerViewController : UIViewController
7171// took focus from an input that has stopped answering the accessibility query that found it.
7272@property (nonatomic , strong ) UILabel *textEntryFocusWitness;
7373@property (nonatomic , assign ) NSUInteger textEntryWriteBacks;
74+ @property (nonatomic , assign ) NSUInteger textEntryTotalEdits;
7475@property (nonatomic , copy , nullable ) NSString *textEntryRenderedValue;
7576@property (nonatomic , assign ) NSTimeInterval textEntryLastEditTime;
7677@property (nonatomic , assign ) NSTimeInterval textEntryBurstStartTime;
@@ -106,6 +107,16 @@ - (NSString *)accessibilityValue {
106107@interface AgentDeviceDigitGroupingTextField : UITextField <UITextFieldDelegate>
107108@end
108109
110+ @interface AgentDeviceCurrencyTextField : UITextField <UITextFieldDelegate>
111+ @property (nonatomic , strong ) UILabel *entryStatus;
112+ @property (nonatomic , assign ) NSUInteger insertedDigits;
113+ @end
114+
115+ @interface AgentDeviceSubmitClearingTextField : UITextField <UITextFieldDelegate>
116+ @property (nonatomic , strong ) UILabel *entryStatus;
117+ @property (nonatomic , assign ) NSUInteger submits;
118+ @end
119+
109120static NSString *AgentDeviceFormatGroupedDigits (NSString *raw) {
110121 NSMutableString *digits = [NSMutableString string ];
111122 NSCharacterSet *nonDigits = [[NSCharacterSet decimalDigitCharacterSet ] invertedSet ];
@@ -176,6 +187,33 @@ - (BOOL)textField:(UITextField *)textField
176187 return NO ;
177188}
178189@end
190+
191+ @implementation AgentDeviceCurrencyTextField
192+ - (BOOL )textField : (UITextField *)textField
193+ shouldChangeCharactersInRange : (NSRange )range
194+ replacementString : (NSString *)string {
195+ NSString *combined = [textField.text stringByReplacingCharactersInRange: range withString: string];
196+ NSMutableString *digits = [NSMutableString string ];
197+ for (NSString *part in [combined componentsSeparatedByCharactersInSet: NSCharacterSet .decimalDigitCharacterSet.invertedSet]) {
198+ [digits appendString: part];
199+ }
200+ unsigned long long cents = digits.longLongValue ;
201+ textField.text = [NSString stringWithFormat: @" $%llu .%02llu " , cents / 100 , cents % 100 ];
202+ self.insertedDigits += AgentDeviceDigitCount (string, string.length );
203+ self.entryStatus .text = [NSString stringWithFormat: @" %lu " , (unsigned long )self .insertedDigits];
204+ textField.selectedTextRange = [textField textRangeFromPosition: textField.endOfDocument toPosition: textField.endOfDocument];
205+ return NO ;
206+ }
207+ @end
208+
209+ @implementation AgentDeviceSubmitClearingTextField
210+ - (BOOL )textFieldShouldReturn : (UITextField *)textField {
211+ self.submits += 1 ;
212+ self.entryStatus .text = [NSString stringWithFormat: @" %lu " , (unsigned long )self .submits];
213+ textField.text = @" " ;
214+ return YES ;
215+ }
216+ @end
179217#endif
180218
181219@implementation AgentDeviceRunnerViewController
@@ -281,11 +319,12 @@ - (void)updateAlertActionStatus {
281319- (void )updateTextEntryWriteBackStatus {
282320 NSTimeInterval burstSpan = self.textEntryLastEditTime - self.textEntryBurstStartTime ;
283321 self.textEntryWriteBackStatus .text = [NSString
284- stringWithFormat: @" write-backs=%lu burst-edits=%lu burst-ms=%lu min-gap-ms=%lu " ,
322+ stringWithFormat: @" write-backs=%lu burst-edits=%lu burst-ms=%lu min-gap-ms=%lu total-edits= %lu " ,
285323 (unsigned long )self .textEntryWriteBacks,
286324 (unsigned long )self .textEntryBurstEdits,
287325 (unsigned long )llround (burstSpan * 1000 ),
288- (unsigned long )llround (self .textEntryBurstMinGap * 1000 )];
326+ (unsigned long )llround (self .textEntryBurstMinGap * 1000 ),
327+ (unsigned long )self .textEntryTotalEdits];
289328}
290329
291330- (void )presentAlertFixtureReplacement : (BOOL )replacement {
@@ -371,6 +410,7 @@ - (void)agentDeviceTextEntryDidChange:(UITextField *)textField {
371410 // typed faster than the app renders loses the characters that arrived while a render was in
372411 // flight, and the field settles stable short of the request.
373412 if ([NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-app-owned-value" ]) {
413+ self.textEntryTotalEdits += 1 ;
374414 NSTimeInterval now = NSProcessInfo .processInfo .systemUptime ;
375415 NSTimeInterval gap = now - self.textEntryLastEditTime ;
376416 BOOL overtookARender = self.textEntryRenderedValue != nil && gap < self.textEntryAcknowledgeWindowSeconds ;
@@ -489,16 +529,24 @@ - (void)viewDidLoad {
489529 [NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-digit-count-value" ];
490530 BOOL digitGroupingValue =
491531 [NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-digit-grouping-value" ];
532+ BOOL currencyValue =
533+ [NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-currency-value" ];
534+ BOOL submitClears =
535+ [NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-submit-clears" ];
492536 UITextField *textField;
493537 if (digitCountValue) {
494538 textField = [[AgentDeviceDigitCountTextField alloc ] init ];
495539 } else if (digitGroupingValue) {
496540 textField = [[AgentDeviceDigitGroupingTextField alloc ] init ];
541+ } else if (currencyValue) {
542+ textField = [[AgentDeviceCurrencyTextField alloc ] init ];
543+ textField.text = @" $0.00" ;
544+ } else if (submitClears) {
545+ textField = [[AgentDeviceSubmitClearingTextField alloc ] init ];
497546 } else {
498547 textField = [[UITextField alloc ] init ];
499548 }
500- if (digitGroupingValue) {
501- // The formatter field is its own delegate: every edit is reformatted before it lands.
549+ if (digitGroupingValue || currencyValue || submitClears) {
502550 textField.delegate = (id <UITextFieldDelegate>)textField;
503551 }
504552 if (![NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-unnamed-input" ]) {
@@ -525,6 +573,22 @@ - (void)viewDidLoad {
525573 [textField.widthAnchor constraintEqualToConstant: 240 ],
526574 [textField.heightAnchor constraintEqualToConstant: AgentDeviceTextEntryFieldHeight],
527575 ]];
576+ if (currencyValue || submitClears) {
577+ UILabel *entryStatus = [[UILabel alloc ] init ];
578+ entryStatus.accessibilityIdentifier = @" agent-device-text-entry-events" ;
579+ entryStatus.text = @" 0" ;
580+ entryStatus.translatesAutoresizingMaskIntoConstraints = NO ;
581+ [self .view addSubview: entryStatus];
582+ [NSLayoutConstraint activateConstraints: @[
583+ [entryStatus.centerXAnchor constraintEqualToAnchor: self .view.centerXAnchor],
584+ [entryStatus.topAnchor constraintEqualToAnchor: textField.bottomAnchor constant: 12 ],
585+ ]];
586+ if (currencyValue) {
587+ ((AgentDeviceCurrencyTextField *)textField).entryStatus = entryStatus;
588+ } else {
589+ ((AgentDeviceSubmitClearingTextField *)textField).entryStatus = entryStatus;
590+ }
591+ }
528592 if ([NSProcessInfo .processInfo.arguments containsObject: @" --agent-device-text-entry-unqueryable-on-focus" ]) {
529593 self.textEntryFocusWitness = [[UILabel alloc ] init ];
530594 self.textEntryFocusWitness .accessibilityIdentifier = @" agent-device-text-entry-focus" ;
0 commit comments