Temporary workaround to fix NSView losing focus caused by Apple intelligence writing tools

Commit: f8ec61d5 | 2025-03-19 02:17:37+00:00

← Back to List

Temporary workaround to fix NSView losing focus caused by Apple intelligence writing tools

Minor
Commit Hash: f8ec61d5d8112faa755f17ee1c170f9b778679f6
Commit Time: 2025-03-19 02:17:37+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This submission adds a compatibility code segment for the Apple intelligence writing tool in the -[RenderWidgetHostViewCocoa insertText:replacementRange:] method of content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm. The code checks whether the current window’s firstResponder is NSRemoteView and its parent view is WTWritingToolsView. If so, it forcibly makes itself (i.e., the content’s NSView) become the firstResponder again. This prevents the content view from losing focus after the user clicks the “Replace” button in the writing tool bubble, which would otherwise cause the replacement text to fail to be correctly inserted by the IME. This change is a temporary workaround and can be removed once Apple provides an official fix.

🎯 Impact Analysis

This change directly enhances the compatibility of WebView2Mac in scenarios integrating Apple intelligence writing tools, ensuring that users do not encounter input anomalies caused by NSView losing focus when replacing text via the writing tool. Since WebView2Mac relies on render_widget_host_view_cocoa.mm to handle input method and text insertion logic, this fix prevents text insertion failures resulting from lost input focus. The change only affects focus management in specific scenarios and does not impact other Remote Cocoa-related functions or performance. It is a backward-compatible patch with low risk.

Impacted Classes:

RenderWidgetHostViewCocoa