Text manipulation: ignore leading and trailing spaces when comparing content for all tokens
https://bugs.webkit.org/show_bug.cgi?id=223057
<rdar://73706436>

Reviewed by Ryosuke Niwa.

Source/WebCore:

In r265361, we started to ignore leading and trailing spaces for first and last tokens in a paragraph. That's
not enough because one paragraph can also contain multiple nodes. Space between two nodes may be collapsed when
two nodes become separated by a new line. In the added test: the space after 'and' is collapsed when div's width
is changed, because TextManipulationController ignores collapsed space, it would compare ' and' with ' and ',
and returns ContentChanged error.

API test: TextManipulation.CompleteTextManipulationParagraphContainsCollapsedSpaces

* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::replace):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@274282 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TextManipulationController.cpp b/Source/WebCore/editing/TextManipulationController.cpp
index 6ef9fe0..49a5cff 100644
--- a/Source/WebCore/editing/TextManipulationController.cpp
+++ b/Source/WebCore/editing/TextManipulationController.cpp
@@ -818,12 +818,7 @@
                 return ManipulationFailureType::ContentChanged;
 
             auto& currentToken = item.tokens[currentTokenIndex++];
-            bool isContentUnchanged = currentToken.content == token.content;
-            if (!UNLIKELY(isContentUnchanged)) {
-                bool isFirstOrLastToken = currentTokenIndex == 1 || currentTokenIndex == item.tokens.size();
-                isContentUnchanged = isFirstOrLastToken && areEqualIgnoringLeadingAndTrailingWhitespaces(currentToken.content, token.content);
-            }
-
+            bool isContentUnchanged = areEqualIgnoringLeadingAndTrailingWhitespaces(currentToken.content, token.content);
             if (!content.isReplacedContent && !isContentUnchanged)
                 return ManipulationFailureType::ContentChanged;