What programmatic access to we have to writing tools?

Asked on 2024-07-29

1 search

Programmatic access to writing tools is provided through various APIs and delegate methods. Here are the key points:

  1. Integration with Native Text Views:

    • Writing tools work seamlessly with UITextView, NSTextView, and WKWebView when using the appropriate configurations.
    • For UITextView and NSTextView, using TSC2 is recommended for the full experience. TSC1 provides a limited experience with results shown in a panel.
  2. Custom Text Views:

    • For custom text views, you can adopt the NSServicesMenuRequester protocol to allow the system to read and write contents to the view.
    • Implement the validRequestor(forSendType:returnType:) method to handle rich text and ensure the writing tools menu item appears in the context menu.
  3. Controlling Behavior:

    • Use the new text input traits API to customize the behavior of writing tools. You can set the behavior to limited for a panel experience or none to opt out completely.
    • Specify if your text view supports rich text or tables using RankToolsAllowedInputOptions.
  4. Protecting Ranges:

    • Delegate methods in UITextFieldDelegate and NSTextViewDelegate allow you to specify ranges of text that should be ignored by writing tools, such as code blocks or quoted content.
  5. Observing Writing Tools Activity:

    • Check or observe the isWritingToolsActive property to know if a writing tool session is active.
    • Use new delegate methods to manage app states during a writing tools session, such as pausing syncing to avoid conflicts.

For more detailed information, you can refer to the session "Get started with Writing Tools".

Relevant Sessions