Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c093ebec8aa0c8f222e03be281957c5010edf6ed
      
https://github.com/WebKit/WebKit/commit/c093ebec8aa0c8f222e03be281957c5010edf6ed
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-08-20 (Thu, 20 Aug 2026)

  Changed paths:
    A 
LayoutTests/editing/mac/spelling/context-menu-spelling-guess-input-events-expected.txt
    A 
LayoutTests/editing/mac/spelling/context-menu-spelling-guess-input-events.html
    M Source/WebCore/page/ContextMenuController.cpp
    M Source/WebKit/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Source/WebKit/WebProcess/WebPage/WebPage.h

  Log Message:
  -----------
  Choosing a spelling suggestion from the context menu fires inputType 
'insertText' instead of 'insertReplacementText'
https://bugs.webkit.org/show_bug.cgi?id=195846
rdar://166940428

Reviewed by Wenson Hsieh.

Picking a suggestion from the context menu for a misspelled word fired
"insertText" rather than "insertReplacementText":

      beforeinput: inputType=insertText data=null dataTransfer="welcome"

Input Events Level 2 [1] section 6.1.2 defines the row as:

      inputType                 | User's expression of intention
      "insertReplacementText"   | insert or replace existing content by means of
                                | a spell checker, auto-correct, writing
                                | suggestions or similar

with "Part of IME composition: No", "beforeinput cancelable: Yes" and "State of
selection: Any". A context menu spelling suggestion is squarely a spell checker
replacement, so this is the correct inputType. The W3C Editing Task Force
reached the same conclusion in [2]: "seems like a bug. probably should be
insertReplacementText".

EditAction::InsertReplacement already maps to "insertReplacementText" in
inputTypeNameForEditingAction(), and the automatic autocorrection popover
already used it by way of SpellingCorrectionCommand. The context menu handler
simply never passed it, so it took ReplaceSelectionCommand::create()'s default
of EditAction::Insert.

Pass EditAction::InsertReplacement instead. The switch is otherwise inert:
undoRedoLabel() returns the empty string for both, CompositeEditCommand::apply()
accepts both in plain text, AlternativeTextController::respondToAppliedEditing()
does not inspect the action, and the bidi-paste and accessibility paths in
ReplaceSelectionCommand only test for Paste and InsertFromDrop.

WebPage::changeSpellingToWord() had the same defect from the Spelling and
Grammar panel's Change button, so thread an EditAction through
WebPage::replaceSelectionWithText(). Its only other caller,
applyTextTransformation() (Make Upper Case, Capitalize, Chinese conversion),
stays on EditAction::Insert since those are not "a spell checker, auto-correct,
writing suggestions or similar". That path is only reachable from the panel,
which no layout test can drive, so it is covered by inspection rather than by
the new test.

Only the inputType was wrong; the attribute values already conformed. Per the
data table in [1], "insertReplacementText" carries "the plain text string to be
inserted" only for an "input or textarea" editing host and otherwise falls to
"All remaining | Any | null", while the dataTransfer table gives it "a
prepopulated DataTransfer object" only for a "contenteditable" host and
otherwise "null". WebKit already matched both directions, and beforeinput is
cancelable as the table requires. The new test asserts all of it.

The forward declaration added to WebPage.h is needed because the existing
EditAction declared in that header is WebCore::WritingTools::EditAction.

[1] https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes
[2] https://github.com/w3c/editing/issues/494

Test: editing/mac/spelling/context-menu-spelling-guess-input-events.html

* 
LayoutTests/editing/mac/spelling/context-menu-spelling-guess-input-events-expected.txt:
 Added.
* 
LayoutTests/editing/mac/spelling/context-menu-spelling-guess-input-events.html: 
Added.
* Source/WebCore/page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
* Source/WebKit/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm:
(WebKit::applyTextTransformation):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::changeSpellingToWord):
(WebKit::WebPage::replaceSelectionWithText):
* Source/WebKit/WebProcess/WebPage/WebPage.h:

Canonical link: https://commits.webkit.org/319540@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to