Skip to content

API Review: Custom context menu Spellcheck#5553

Open
anuragkumar878 wants to merge 6 commits intomainfrom
user/kumaranurag/custom_context_menu_spellcheck_integration
Open

API Review: Custom context menu Spellcheck#5553
anuragkumar878 wants to merge 6 commits intomainfrom
user/kumaranurag/custom_context_menu_spellcheck_integration

Conversation

@anuragkumar878
Copy link
Copy Markdown

@anuragkumar878 anuragkumar878 commented Mar 31, 2026

SpellCheck Suggestions for Custom Context Menus

Enables host apps rendering custom context menus to asynchronously retrieve and apply spellcheck suggestions for misspelled words in editable fields.

New Interfaces:

ICoreWebView2ContextMenuRequestedEventArgs2 extends ICoreWebView2ContextMenuRequestedEventArgs

  • GetSpellCheckSuggestionsAsync(handler) : Registers a one-shot completion handler that fires exactly once with spellcheck suggestions. Fires immediately if suggestions are already resolved, or deferred until ready.
  • ApplySpellCheckSuggestion(suggestion) : Replaces the misspelled word in the focused editable field with the given suggestion. Handles cross-frame routing internally.

ICoreWebView2GetSpellCheckSuggestionsCompletedHandler

  • Invoke(errorCode, suggestions) — Callback delivering an HRESULT and an ICoreWebView2StringCollection of suggestion strings.

Usage flow:

  1. Host receives ContextMenuRequested
  2. Calls GetSpellCheckSuggestionsAsync with a handler
  3. Handler fires with suggestions -> host populates menu
  4. User selects -> host calls ApplySpellCheckSuggestion

No synchronous readiness query, the single async call covers both immediate and deferred resolution.

@anuragkumar878
Copy link
Copy Markdown
Author

anuragkumar878 commented Mar 31, 2026

@microsoft-github-policy-service agree company="Microsoft"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new API review spec to extend the existing WebView2 ContextMenuRequested customization flow with spellcheck support, enabling hosts that render custom context menus to surface and apply spellcheck suggestions.

Changes:

  • Adds a new spec describing custom-context-menu spellcheck scenarios and motivation.
  • Provides Win32 C++ and C# example flows for querying suggestions, handling async readiness, and applying a suggestion.
  • Proposes new Win32 COM interfaces (ICoreWebView2ContextMenuTarget2, ICoreWebView2ContextMenuRequestedEventArgs2) plus corresponding .NET/WinRT projections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MicrosoftEdge MicrosoftEdge deleted a comment from Copilot AI Apr 1, 2026
@anuragkumar878 anuragkumar878 added the API Proposal Review WebView2 API Proposal for review. label Apr 1, 2026
@anuragkumar878 anuragkumar878 marked this pull request as ready for review April 1, 2026 10:33
@anuragkumar878 anuragkumar878 requested a review from Copilot April 2, 2026 04:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

2. Apply a selected spellcheck suggestion to replace the misspelled word in the DOM.

The design uses a purely asynchronous approach: the host always calls `GetSpellCheckSuggestionsAsync`
which fires the handler exactly once either immediately (if suggestions are already resolved) or
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the description, there’s an extra space in “exactly once either” which reads like a typo. Please change to a single space (and consider adding a comma after “once” for readability).

Suggested change
which fires the handler exactly once either immediately (if suggestions are already resolved) or
which fires the handler exactly once, either immediately (if suggestions are already resolved) or

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +19
The design uses a purely asynchronous approach: the host always calls `GetSpellCheckSuggestionsAsync`
which fires the handler exactly once either immediately (if suggestions are already resolved) or
when they become available. There is no synchronous readiness query.
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec describes a “purely asynchronous approach”, but later states the completion handler may be invoked “immediately and synchronously” when suggestions are already resolved. This is a behavioral contract issue (reentrancy) for hosts; please make the contract consistent by either guaranteeing asynchronous invocation (posted) or explicitly documenting that the callback may run inline and callers must be reentrancy-safe.

Copilot uses AI. Check for mistakes.
Comment on lines +147 to +151
/// the handler is invoked immediately and synchronously.
/// The handler receives `S_OK` and the suggestions collection on success,
/// or an error HRESULT and `nullptr` on failure.
/// Only one handler can be registered at a time; calling this method again
/// replaces any previously registered handler.
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The COM API states that only one handler can be registered at a time and subsequent calls replace the prior handler. This differs from other WebView2 async-with-handler patterns (which typically allow multiple concurrent calls and invoke all handlers) and also doesn’t map cleanly to the WinRT projection where each call returns a distinct IAsyncOperation. Consider aligning with existing WebView2 semantics (e.g., multiple calls before completion all complete together; after completion, complete immediately) or clearly defining cancellation/overwriting behavior in both COM and WinRT surfaces.

Suggested change
/// the handler is invoked immediately and synchronously.
/// The handler receives `S_OK` and the suggestions collection on success,
/// or an error HRESULT and `nullptr` on failure.
/// Only one handler can be registered at a time; calling this method again
/// replaces any previously registered handler.
/// the handler is invoked immediately and synchronously with the cached
/// suggestions.
/// The handler receives `S_OK` and the suggestions collection on success,
/// or an error HRESULT and `nullptr` on failure.
/// Multiple calls to this method are allowed. All handlers registered before
/// suggestions are resolved are invoked when results become available, and
/// calls made after resolution complete immediately using the cached results.

Copilot uses AI. Check for mistakes.
};

// ... add other menu items, show contextMenu ...
deferral.Complete();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the .NET/WinRT example, deferral.Complete() is called immediately after registering the async completion handler. For custom context menus, existing guidance is to hold the deferral until the menu is dismissed or a command is executed (see specs/ContextMenuRequested.md around the custom UI example where the deferral is completed on menu close). Completing early risks the args/context being invalid before suggestions are applied.

Suggested change
deferral.Complete();
contextMenu.Closed += (_, _) => deferral.Complete();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Proposal Review WebView2 API Proposal for review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants