Skip to content

API Review: Custom context menu Spellcheck#5553

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

API Review: Custom context menu Spellcheck#5553
anuragkumar878 wants to merge 9 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.

Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

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

Review Summary

The architecture and design are sound — DeferredCapabilityDiscovery, ContextMenuItemCollection return type, unified SelectedCommandId commanding, and always-async callback are all well done. The comments below focus on bringing the spec up to the polish expected for Windows API review board submission:

Must fix:

  • Placeholder UUIDs (lines 260, 298, 320) — generate real values
  • .NET projection should use [interface_name] pattern, not EventArgs2 class (line 363)
  • Verify MIDL3 format requirement with SDK team (line 233)

Should fix:

  • Rename title to "Spellcheck Support for Custom Context Menus"
  • Complete the samples (both C++ and C# have undefined helpers / placeholder comments)
  • Add CHECK_FAILURE() consistently in C++ sample
  • Fix SelectedCommandId default value in error table (it's -1, not 0)

Nit:

  • Consistent casing of "spellcheck" in prose
  • Avoid contractions per Microsoft style guide
  • Use /// doc comments in .NET projection
  • Clean up casual language ("for example -")

@@ -0,0 +1,453 @@
Custom Context Menu SpellCheck
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Title: Consider renaming to "Spellcheck Support for Custom Context Menus". The current title "Custom Context Menu SpellCheck" reads as if you're customizing a spellcheck menu, rather than adding spellcheck to custom context menus. The revised title puts the feature (spellcheck support) first and the context (custom context menus) second, which better matches how the feature is described in the Background section.

@@ -0,0 +1,453 @@
Custom Context Menu SpellCheck
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: "SpellCheck" uses inconsistent casing — the rest of the spec uses "spellcheck" (lowercase) or "Spellcheck" (sentence case). Pick one and use it consistently. The IDL uses SpellCheck (PascalCase) for type names, which is correct, but prose should use lowercase "spellcheck" per Microsoft style guide (common nouns are not capitalized).


- **`MisspelledWord`** — Read-only property returning the misspelled word under the cursor. Useful for
displaying "Suggestions for 'teh':" headers in custom menus.
- **`GetSpellCheckSuggestionsAsync`** — Retrieves suggestions as `ICoreWebView2ContextMenuItem` objects.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Style: Microsoft documentation avoids contractions. Change "doesn't" → "does not". (See Microsoft Style Guide - Contractions)

// Inside ContextMenuRequested handler for an editable field:

// ── Step 1: Runtime version check ──
auto args2 = wil::try_com_query<
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The existing ContextMenuRequested.md spec in this repo uses more descriptive example headings like "Win32 C++ Use Data to Display Custom Context Menu." Consider something like "Win32 C++ — Display Custom Context Menu with Spellcheck Suggestions" to match the established pattern and make it immediately clear what the example demonstrates.

auto args2 = wil::try_com_query<
ICoreWebView2ContextMenuRequestedEventArgs2>(args);
if (!args2)
return S_OK; // Old runtime — use default menu.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This sample is a code fragment — it starts mid-handler and uses undefined helpers (ShowPopupAtCursor, AddMenuItems). The existing ContextMenuRequested.md spec shows complete, self-contained examples with the full �dd_ContextMenuRequested registration, lambda body, and helper implementations. This sample should be complete enough to compile (with the standard WebView2 boilerplate). At minimum, show the full event handler registration wrapping this code.

/// This is the word that spellcheck flagged as incorrect and for which
/// suggestions are available via `GetSpellCheckSuggestionsAsync`.
/// The caller must free the returned string using `CoTaskMemFree`.
///
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

�4a8f3b2-6c1d-4e9a-b5f7-2d8c9a0e1b34 — another placeholder. All three interface UUIDs need real values before this goes to API review.

namespace Microsoft.Web.WebView2.Core
{
[Flags]
enum CoreWebView2ContextMenuDeferredCapabilities
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The .NET/WinRT API definition uses // comments (C# style) instead of /// doc comments. WebView2 specs use /// for API documentation in the .NET projection. For example:
csharp /// <summary> /// The misspelled word under the cursor. /// </summary> String MisspelledWord { get; };
Also, CoreWebView2ContextMenuRequestedEventArgs2 : CoreWebView2ContextMenuRequestedEventArgs — WebView2's .NET projection does not use numbered EventArgs2 classes. New members are added to the existing CoreWebView2ContextMenuRequestedEventArgs class with an [interface_name] attribute block, as seen in ContextMenuRequested.md. Should be:
`csharp
runtimeclass CoreWebView2ContextMenuRequestedEventArgs
{
// Existing members unchanged.

[interface_name("ICoreWebView2ContextMenuRequestedEventArgs2")]
{
    CoreWebView2ContextMenuDeferredCapabilities DeferredCapabilities { get; };
    T GetDeferredCapability<T>();
}

}
`

| User dismisses menu without selecting | Set `SelectedCommandId` to 0 or simply complete the deferral |

# Appendix

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"Spellcheck applicable but word is empty — defensive check recommended" — if the SPELL_CHECK flag is set but MisspelledWord is empty, that is a bug, not a normal state. This row should say the behavior is undefined/unexpected and the host should treat it as "no spellcheck." Don't normalize buggy state as expected behavior in an API spec.


## Extensibility

The deferred capability pattern introduced by this feature is designed for zero-versioning extension:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"Set SelectedCommandId to 0 or simply complete the deferral" — the "or" is ambiguous. The existing ContextMenuRequested.md spec says the default SelectedCommandId is -1 (not 0), meaning no selection. Clarify: "Do not set SelectedCommandId (its default value of -1 indicates no selection) and complete the deferral."

## Planned SpellCheck Extensions

The following actions will be added as additional `ICoreWebView2ContextMenuItem` entries in the
collection returned by `GetSpellCheckSuggestionsAsync`. No new interfaces or methods are required:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: "for example - " is casual tone. In Microsoft documentation style, use "For example:" or just show the value directly without the prefix.

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.

3 participants