Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6cd1f4e75e31195246920f7fba52d3003fe08e9d
      
https://github.com/WebKit/WebKit/commit/6cd1f4e75e31195246920f7fba52d3003fe08e9d
  Author: Wenson Hsieh <[email protected]>
  Date:   2024-05-06 (Mon, 06 May 2024)

  Changed paths:
    A 
LayoutTests/editing/input/mac/do-not-allow-inline-predictions-if-text-changes-expected-mismatch.html
    A 
LayoutTests/editing/input/mac/do-not-allow-inline-predictions-if-text-changes.html
    M LayoutTests/platform/mac-wk2/TestExpectations
    M Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
    M Source/WebCore/editing/Editor.h
    M Source/WebCore/editing/VisibleSelection.cpp
    M Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h
    M Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/UIProcess/mac/WebViewImpl.h
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Source/WebKit/WebProcess/WebPage/WebPage.h
    M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
    M Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
    M Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

  Log Message:
  -----------
  Letters disappear randomly while typing in Stash when writing suggestions are 
enabled
https://bugs.webkit.org/show_bug.cgi?id=273748
rdar://127392270

Reviewed by Richard Robinson.

Stash's JavaScript listens for `keydown` events and, in response, replaces text 
nodes right before
the selection in the editable container when writing comments. This interferes 
with both current
implementations of writing suggestions (i.e. inline predictions), which depend 
on the text node
before the user's selection being the same, as the user types.

We can detect this case by computing and remembering the last node before the 
user's selection after
each editing keyboard event (where writing suggestions would normally be 
inserted). If this text
node changes in between the last key event and when sending the next editor 
state after changing the
selection, then don't allow writing suggestions.

* 
LayoutTests/editing/input/mac/do-not-allow-inline-predictions-if-text-changes-expected-mismatch.html:
 Added.
* 
LayoutTests/editing/input/mac/do-not-allow-inline-predictions-if-text-changes.html:
 Added.

Add a layout test to exercise the new heuristic.

* LayoutTests/platform/mac-wk2/TestExpectations:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:

Remove the internal `InlinePredictionsInAllEditableElementsEnabled` setting. 
This was only used to
test writing suggestions on the web, before enabling it by default.

* Source/WebCore/editing/Editor.h:
* Source/WebCore/editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::canEnableWritingSuggestions const):

Make the `writingsuggestions` state in editable elements follow the enclosing 
text form control, if
applicable. This is needed to keep 
`WritingSuggestionsWebAPI.DefaultStateWithDisabledAutocomplete`
passing after the change to consult `EditorState` in `-[WKContentView 
_updateTextInputTraits:]`, now
that we don't solely depend on the initial focused element information.

* Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h:
* Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm:
(-[WKWebView _allowsInlinePredictions]):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _updateTextInputTraits:]):

Make the iOS codepath honor editor state's writing suggestions enablement flag 
(which may change on
the fly, unlike focused element information).

* Source/WebKit/UIProcess/mac/WebViewImpl.h:
* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::allowsInlinePredictions const):

Remove logic to honor the (now-removed) internal feature flag, and simplify the 
logic a bit.

* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::getPlatformEditorStateCommon const):

Consult `m_lastNodeBeforeWritingSuggestions` when computing 
`canEnableWritingSuggestions` on the
`EditorState`'s post-layout data. If the current node has changed since the 
last key event, avoid
trying to compute and inject writing suggestions.

* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didCommitLoad):

Reset `m_lastNodeBeforeWritingSuggestions`.

(WebKit::WebPage::updateLastNodeBeforeWritingSuggestions):

Add a helper method to update `m_lastNodeBeforeWritingSuggestions` after a 
`keydown`.

* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::handleEditingKeyboardEvent):
* Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::handleEditingKeyboardEvent):

Call the helper method above when handling keyboard editing.

* Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::setInlinePrediction):

Make this a no-op when `-_allowsInlinePredictions` is `NO`, so that we can 
(somewhat indirectly)
test the new logic to avoid writing suggestions in the case where the text node 
before the selection
keeps changing after each key event.

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to