RESOLVED FIXED 279888
AX: Support multiple replacement strings in AXTextOperation
https://bugs.webkit.org/show_bug.cgi?id=279888
Summary AX: Support multiple replacement strings in AXTextOperation
Samar Sunkaria
Reported 2024-09-18 06:49:40 PDT
WebKit’s `AXTextOperation` parameterized accessibility attribute, among its other capabilities, lets you replace text across multiple text marker ranges in an editable text field. It takes a dictionary as its parameter, with the `AXTextOperationMarkerRanges` key indicating an array of text marker ranges to be replaced, and the `AXTextOperationReplacementString` key indicating the (one) replacement string. The existing API mirrors the contract for a simple find-and-replace operation. Utilizing `AXSearchTextWithCriteria`, you can locate text marker ranges for a search string and, substitute them with a replacement string using `AXTextOperation`. However, `AXTextOperation`’s usability is severely limited beyond this specific use case. Adding the ability to replace individual ranges with different replacement strings would be a great enhancement to `AXTextOperation`. This would allow it to be used outside the narrow scope of a simple find-and-replace operation, enabling richer replacements from an accessibility client. While the same result can be achieved by chaining multiple calls to AXTextOperation, it is comparatively much slower to do that. This can be achieved by adding a new key to the `AXTextOperation` parameter dictionary (such as `AXTextOperationIndividualReplacementStrings`), which expects an array of strings as its value. This array is expected to have the same length as the `AXTextOperationMarkerRanges` array, where each replacement string corresponds to one replacement range. ``` // Editable text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. // To replace "dolor" -> "foo" and "elit" -> "bar": CFTypeRef result; AXUIElementCopyParameterizedAttributeValue(element, "AXTextOperation", @[ NSAccessibilityTextOperationType: NSAccessibilityTextOperationReplace, NSAccessibilityTextOperationIndividualReplacementStrings: @[ @"bar", @"foo" ], NSAccessibilityTextOperationMarkerRanges: @[ rangeOfElit, rangeOfDolor ] ], &result) ``` Since this is an additive change, the existing clients of `AXTextOperation` will remain unaffected. The existing `AXTextOperationReplacementString` key for providing a single replacement string will continue to work as expected.
Attachments
Radar WebKit Bug Importer
Comment 1 2024-09-18 06:49:53 PDT
Samar Sunkaria
Comment 2 2024-09-18 09:22:36 PDT
Samar Sunkaria
Comment 3 2024-09-20 07:06:56 PDT
Grammarly intends to use this new attribute parameter key.
EWS
Comment 4 2024-09-21 15:59:12 PDT
Committed 284044@main (f20ec536521f): <https://commits.webkit.org/284044@main> Reviewed commits have been landed. Closing PR #33837 and removing active labels.
EWS
Comment 5 2024-09-24 12:03:19 PDT
Committed 283286.121@safari-7620-branch (4c0e2c82c1e2): <https://commits.webkit.org/283286.121@safari-7620-branch> Reviewed commits have been landed. Closing PR #1894 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.