Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 92da80f85aff418abc9af18eaaac43613e5dc502
      
https://github.com/WebKit/WebKit/commit/92da80f85aff418abc9af18eaaac43613e5dc502
  Author: Ryosuke Niwa <[email protected]>
  Date:   2026-05-22 (Fri, 22 May 2026)

  Changed paths:
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Tools/Scripts/webkitpy/api_tests/allowlist.txt
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm

  Log Message:
  -----------
  REGRESSION(310826@main): Cannot type with Hindi - InScript in Mail
https://bugs.webkit.org/show_bug.cgi?id=315381
dar://177229173

Reviewed by Wenson Hsieh.

This PR fixes a bug that typing kd/e with "Hindi - InScript" input source 
produces क्ा instead of क्या
(the य is dropped), which is a regression from 310826@main.

"Hindi - InScript" input method does a two-phase commit for "/":
  - d keystroke (keyCode=2, chars=""): setMarkedText:"्" — starts composition 
for the virama
  - / keystroke (keyCode=44, chars="्य" length=2): insertText:"्" length=1 - 
commits the marked virama
    only and expects the keyboard layout to deliver the trailing य

310826@main added if (!hasInsertText) commands.appendVector(additionalCommands) 
in the handled=NO branch.
But for Hindi's "/", the input method returns handled=YES (composition exists), 
so we hit the early-return
if (handled) and never reach the layout pass at all. As a result, the trailing 
य is dropped.

This PR implements the following fixes when the current key events commits 
partial composition:
  1. Force handled=NO so commands flow through the keypress phase, satisfying 
the debug assertion in
     EventHandler::handleTextInputEvent which requires underlyingEvent=keypress.
  2. Changed append condition from if (!hasInsertText) to if (!hasInsertText || 
partial).

However, this fix regresses modeless input methods (e.g. Vietnamese Simple 
Telex and 2-Set Korean) which
was fixed in 313286@main due to two existing flaws in the original fix:
  1. selectedRange arithmetic: Per-command delta was text.length() but for 
insertText:"vi" rep=(0,1),
     the actual cursor advance is 2 − 1 = 1, not 2. So after the 2nd keystroke 
we reported cursor at 3 on
     a 2-char document. The input method cached that, and on the 3rd keystroke 
it sent setMarkedText:"e"
     rep=(2..3,2) addressing past the document end - which is a trigger to give 
up on modeless and falls
     back to composition mode.
  2. attributedSubstring was not staged at all. The input method polls 
attributedSubstring ~6 times per
     keystroke to verify the text it just wrote landed. When the queue defers 
the insertText: IPC,
     the poll returns stale content, and the input method reverts back to 
setMarkedText: for the rest of
     the session even with the cursor position reported correctly.

This PR implements the following fixes for this modeless input method issues:
  a. Per-command delta is text.length() - min(text.length(), 
replacementRange.length) so replacement-range
     commits aren't double-counted.
  b. attributedSubstringForProposedRange applies queued insertText: commands to 
the IPC response (same
     modeless-only gate), so the input method observes the post-keystroke 
document.

Test: 
TestWebKitAPI.WKWebViewMacEditingTests.HindiInScriptViramaConjunctEmitsSuffixFromKeyboardLayoutPass
      
TestWebKitAPI.WKWebViewMacEditingTests.ModelessInputMethodStagingReportsPostKeystrokeCursorAndContent

* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::interpretKeyEvent):
(WebKit::WebViewImpl::selectedRangeWithCompletionHandler):
(WebKit::WebViewImpl::attributedSubstringForProposedRange):
* Tools/Scripts/webkitpy/api_tests/allowlist.txt:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm:
(-[MockTextInputContextAction 
initWithMarkedText:selectedRange:replacementRange:]):
(-[MockTextInputContextAction initWithInsertText:replacementRange:]):
(-[MockTextInputContext handleEventByInputMethod:completionHandler:]):
(-[MockTextInputContext handleEventByKeyboardLayout:]):
(TestWebKitAPI::TEST(WKWebViewMacEditingTests, 
HindiInScriptViramaConjunctEmitsSuffixFromKeyboardLayoutPass)):
(TestWebKitAPI::TEST(WKWebViewMacEditingTests, 
ModelessInputMethodStagingReportsPostKeystrokeCursorAndContent)):

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



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

Reply via email to