Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c50efa2edcdd289ea73b44b0a9ebd1390ad74f01
      
https://github.com/WebKit/WebKit/commit/c50efa2edcdd289ea73b44b0a9ebd1390ad74f01
  Author: Ryosuke Niwa <[email protected]>
  Date:   2026-06-03 (Wed, 03 Jun 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: Can't use 2-Set Korean in Mail
https://bugs.webkit.org/show_bug.cgi?id=316230

Reviewed by Wenson Hsieh.

When typing Korean 2-Set (두벌식) in modeless mode, the input source uses 
insertText: with replacementRange:
rather than setMarkedText:. Mail sets _markedTextInputEnabled = YES, which 
enables inline predictions via
allowsInlinePredictions(). The inline predictions pipeline (NSSpellChecker -> 
IPC -> showCompletionForCandidate:)
can call setMarkedText: on the main thread while 2-Set Korean's 
handleEventByInputMethod: XPC round-trip is in
flight - a window where m_collectedKeypressCommands is non-empty.

When setMarkedText: is called during that window, WebViewImpl queues it and 
sets m_stagedMarkedRange.
2-Set Korean then polls selectedRangeWithCompletionHandler to verify its cursor 
position. That handler captured
m_stagedMarkedRange and computed: `compositionRange.location + 
stagedSelectedRange->location` but because only
modeless insertText: had been used so far, the web process has no composition - 
compositionRange.location is
notFound (SIZE_MAX). Adding any value to SIZE_MAX overflows, producing 
NSNotFound. The Korean IME interprets
NSNotFound as "cursor unknown" and abandons modeless mode for the rest of the 
session, causing "셔ㄷ" to be typed
instead of "셛".

This PR fixes the bug by adding compositionRange.location != notFound guard in 
selectedRangeWithCompletionHandler.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm

* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::selectedRangeWithCompletionHandler):
* Tools/Scripts/webkitpy/api_tests/allowlist.txt:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm:
(TestWebKitAPI::TEST(WKWebViewMacEditingTests, 
ModelessInputMethodStagingReportsPostKeystrokeCursorAndContent)):
(TestWebKitAPI::TEST(WKWebViewMacEditingTests, 
ModelessInputMethodStagingToleratesExternalSetMarkedText)):

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



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

Reply via email to