Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6031db379af6aec30c03b076077c57e1c4b3c93d
      
https://github.com/WebKit/WebKit/commit/6031db379af6aec30c03b076077c57e1c4b3c93d
  Author: Ryosuke Niwa <[email protected]>
  Date:   2026-04-08 (Wed, 08 Apr 2026)

  Changed paths:
    M Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
    M Source/WebKit/UIProcess/mac/WebViewImpl.h
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm

  Log Message:
  -----------
  Fix a regression and turn on correct composition event ordering by default
https://bugs.webkit.org/show_bug.cgi?id=311717

Reviewed by Wenson Hsieh.

When InputMethodUsesCorrectKeyEventOrder is enabled, dead key input (e.g., 
Option+E
followed by 'e' to produce "é") results in the accented character being inserted
twice through two independent mechanisms:

  1. The input method's insertText: call with "é" is collected as a keypress 
command
     and replayed during keypress event processing, inserting "é" into the 
document.
  2. WebViewImpl::collectKeyboardLayoutCommandsForEvent independently 
interprets the
     same key event and produces its own insertText: command for the input, 
which is
     appended to the command list and also executed during keypress processing.

Redundant insertions happen because WebViewImpl::interpretKeyEvent 
unconditionally
merges the commands from collectKeyboardLayoutCommandsForEvent with the commands
from the input method, even if the input method has already provided the final 
text.

This PR addresses this regression by ignoring the commands collected from
collectKeyboardLayoutCommandsForEvent when the input method had already included
the final insertText:, and enables the correct event ordering by default as 
we've
identified other web apps such as Claude was also affected by this bug.

In addition, this PR fixes a bug in MockTextInputContext that we were processing
MockTextInputContextAction in the reverse order. This was not caught with
KeyDownFiresBeforeCompositionEvent because it doesn't check the inserted text
but the new test does.

Finally, change the type of function we queue up in 
m_interpretKeyEventHoldingTank
from a CompletionHandler to a Function since handleEventByInputMethod may never 
call
us when the view is destructed prematurely.

Test: WKWebViewMacEditingTests.KeyDownInsertAccentedCharacterOnce

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::interpretKeyEvent):
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm:
(-[MockTextInputContextAction initWithInsertText:replacementRange:]):
(-[MockTextInputContext handleEventByInputMethod:completionHandler:]):
(TestWebKitAPI::TEST(WKWebViewMacEditingTests, 
KeyDownFiresBeforeCompositionEvent)):
(TestWebKitAPI::TEST(WKWebViewMacEditingTests, 
KeyDownInsertAccentedCharacterOnce)):

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



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

Reply via email to