NSWritingToolsCoordinator issue with text replacement

Hello,

we are currently integrating Writing Tools into our macOS application using NSWritingToolsCoordinator with a custom NSView. Overall, the integration is going well and we are generally satisfied with the API.

However, text replacement is sometimes not using NSWritingToolsCoordinator callback function.

When selecting “Replace” from a preview in a Writing Tools UI popup, the text replacement is performed via the NSTextInputClient callback function (insertText:), which does not seem correct.

This is especially problematic in multi-context scenarios, because NSTextInputClient insertText: does not provide the required information about the Writing tools context being used. As a result, it is not possible to determine which context is being modified when managing more than a single context.

In our view, Writing Tools should consistently use the callback function of NSWritingToolsCoordinator for text replacement, whatever is the action performed. This is essential for properly handling multi-context use cases.

This issue is reproducible with the sample app project provided here https://developer.apple.com/documentation/appkit/enhancing-your-custom-text-engine-with-writing-tools.

If you define a breakpoint in function writingToolsCoordinator:replaceRange:inContext:proposedText:reason:animationParameters:completion: of the Writing tools coordinator, the function is not triggered if text replacement is performed from a preview like for "Summary" with "replace" button. NSWritingToolsCoordinator callback function seems to be called only when text replacement is performed directly inline (in the text view) without external preview so.

i have opened a issue with feedback assistant: FB22401950.

Best regards.

I've tried the sample code with the following steps and don't see the issue:

  1. Build and launch the sample code on my macOS 26.4.1 (25E253) with Xcode 26.4 (17E192).
  2. Select all the text and click the toolbar item on the top-right corner to show the Writing Tools UI.
  3. Click Professional to show the Writing Tools bar; observe that writingToolsCoordinator(_:replace:in:proposedText:reason:animationParameters:completion:) is called several times while the text is updated.
  4. Click Done and observe that writingToolsCoordinator(_:replace:in:proposedText:reason:animationParameters:completion:) is called again.

So everything seems to work as expected for me.

I don't see a “Replace” button in the Writing Tools UI. I don't quite remember if that was an element in an earlier version, but maybe you can check with the latest macOS version if you see the same thing, as described above?

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

NSWritingToolsCoordinator issue with text replacement
 
 
Q