Text fields should not be translated while typing
https://bugs.webkit.org/show_bug.cgi?id=220431
<rdar://problem/71724918>
Reviewed by Tim Horton.
Source/WebCore:
Don't vend text nodes or newly created elements inside input elements for translation (i.e. text manipulation)
if the input element was modified by the user. Note that this check is right before the call to
`observeParagraphs` as opposed to when we schedule the observation update, since edit commands may create
renderers for text nodes and other elements before the `m_lastChangeWasUserEdit` flag has been set.
Test: TextManipulation.StartTextManipulationDoesNotExtractUserModifiedText
* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::scheduleObservationUpdate):
Tools:
Add an API test that modifies text in two input fields (by executing an edit command, and then by
programmatically setting the value attribute). The test verifies that only the latter (programmatic) value
change propagates a text manipulation update to the client layer.
* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@271262 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TextManipulationController.cpp b/Source/WebCore/editing/TextManipulationController.cpp
index 03ea6a3..6ef9fe0 100644
--- a/Source/WebCore/editing/TextManipulationController.cpp
+++ b/Source/WebCore/editing/TextManipulationController.cpp
@@ -605,6 +605,10 @@
for (auto& node : nodesToObserve) {
if (!node->isConnected())
continue;
+
+ if (auto host = makeRefPtr(node->shadowHost()); is<HTMLInputElement>(host.get()) && downcast<HTMLInputElement>(*host).lastChangeWasUserEdit())
+ continue;
+
if (!commonAncestor)
commonAncestor = is<ContainerNode>(node.get()) ? node.ptr() : node->parentNode();
else if (!node->isDescendantOf(commonAncestor.get()))