-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick 6cd1f4e. rdar://127392270
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
- Loading branch information
Showing
17 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
.../editing/input/mac/do-not-allow-inline-predictions-if-text-changes-expected-mismatch.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../../resources/ui-helper.js"></script> | ||
<style> | ||
[contenteditable] { | ||
font-size: 16px; | ||
width: 300px; | ||
height: 100px; | ||
caret-color: transparent; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div contenteditable></div> | ||
<script> | ||
let editor = document.querySelector("[contenteditable]"); | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
addEventListener("load", async () => { | ||
editor.focus(); | ||
if (!window.testRunner) | ||
return; | ||
|
||
for (let character of [..."I want to celeb"]) { | ||
await UIHelper.typeCharacter(character); | ||
await UIHelper.ensurePresentationUpdate(); | ||
} | ||
await UIHelper.setInlinePrediction("celebrate", 5); | ||
await UIHelper.ensurePresentationUpdate(); | ||
testRunner.notifyDone(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
50 changes: 50 additions & 0 deletions
50
LayoutTests/editing/input/mac/do-not-allow-inline-predictions-if-text-changes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../../resources/ui-helper.js"></script> | ||
<style> | ||
[contenteditable] { | ||
font-size: 16px; | ||
width: 300px; | ||
height: 100px; | ||
caret-color: transparent; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div contenteditable></div> | ||
<script> | ||
let editor = document.querySelector("[contenteditable]"); | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
addEventListener("load", async () => { | ||
editor.focus(); | ||
if (!window.testRunner) | ||
return; | ||
|
||
for (let character of [..."I want to celeb"]) { | ||
await UIHelper.typeCharacter(character); | ||
await UIHelper.ensurePresentationUpdate(); | ||
} | ||
await UIHelper.setInlinePrediction("celebrate", 5); | ||
await UIHelper.ensurePresentationUpdate(); | ||
testRunner.notifyDone(); | ||
}); | ||
|
||
let typedText = ""; | ||
editor.addEventListener("keydown", event => { | ||
if (event.key.length > 1) | ||
return; | ||
|
||
typedText += event.key === " " ? "\xa0" : event.key; | ||
setTimeout(() => { | ||
for (let childNode of [...editor.childNodes]) | ||
childNode.remove(); | ||
const newText = document.createTextNode(typedText); | ||
editor.appendChild(newText); | ||
getSelection().setPosition(newText, newText.length); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters