Don't insert spaces at the beginning of a newline when using smart-copy-paste
authormegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2019 00:38:55 +0000 (00:38 +0000)
committermegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2019 00:38:55 +0000 (00:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194070

Source/WebCore:

Reviewed by Tim Horton.

If our inserted content end is at the beginning of a paragraph, do not insert a space.
Also, if our inserted content beginning is at the end of a paragraph, do not insert a space.

Test: editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html

* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):

LayoutTests:

Add test for smart copy paste around newlines.
Rebaseline a test that is dependant on a console log that changes lines.
Add additional helper functions to ui-helper.js.

Reviewed by Tim Horton.

* editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea-expected.txt: Added.
* editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html: Added.
* http/tests/security/anchor-download-block-crossorigin-expected.txt:
* platform/mac/TestExpectations:
* resources/ui-helper.js:
(window.UIHelper.doubleClickAt):
(window.UIHelper.doubleClickAtThenDragTo):
(window.UIHelper.async.selectWordByDoubleTapOrClick):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240829 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html [new file with mode: 0644]
LayoutTests/http/tests/security/anchor-download-block-crossorigin-expected.txt
LayoutTests/platform/mac/TestExpectations
LayoutTests/resources/ui-helper.js
Source/WebCore/ChangeLog
Source/WebCore/editing/ReplaceSelectionCommand.cpp

index f5c4714..9532d87 100644 (file)
@@ -1,3 +1,23 @@
+2019-01-31  Megan Gardner  <megan_gardner@apple.com>
+
+        Don't insert spaces at the beginning of a newline when using smart-copy-paste
+        https://bugs.webkit.org/show_bug.cgi?id=194070
+
+        Add test for smart copy paste around newlines.
+        Rebaseline a test that is dependant on a console log that changes lines.
+        Add additional helper functions to ui-helper.js.
+
+        Reviewed by Tim Horton.
+
+        * editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea-expected.txt: Added.
+        * editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html: Added.
+        * http/tests/security/anchor-download-block-crossorigin-expected.txt:
+        * platform/mac/TestExpectations:
+        * resources/ui-helper.js:
+        (window.UIHelper.doubleClickAt):
+        (window.UIHelper.doubleClickAtThenDragTo):
+        (window.UIHelper.async.selectWordByDoubleTapOrClick):
+
 2019-01-31  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Timeline time range selection sometimes shows 0.000, should be just 0
index 4df547b..95275e4 100644 (file)
@@ -52,6 +52,7 @@ http/tests/cookies/same-site [ Skip ]
 system-preview [ Skip ]
 editing/images [ Skip ]
 pointerevents/ios [ Skip ]
+editing/pasteboard/mac [ Skip ]
 
 # window.showModalDialog is only tested in DumpRenderTree on Mac.
 editing/execCommand/show-modal-dialog-during-execCommand.html [ Skip ]
diff --git a/LayoutTests/editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea-expected.txt b/LayoutTests/editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea-expected.txt
new file mode 100644 (file)
index 0000000..a293655
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS selectFirstLineIncludingLineBreak(); copyPaste(); textarea.selectionEnd is offsetAfterLineBreak
+
diff --git a/LayoutTests/editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html b/LayoutTests/editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html
new file mode 100644 (file)
index 0000000..7599f45
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<body>
+<textarea id="test" cols=50 rows=10>first
+second</textarea>
+<script src="../../../resources/js-test-pre.js"></script>
+<script src="../../editing.js"></script>
+<script src="../../../resources/ui-helper.js"></script>
+<p id="console"></p>
+<script>
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var textarea = document.querySelector('textarea');
+
+function selectFirstLineIncludingLineBreak() {
+    var element = document.getElementById("test");
+    const boundingRect = element.getBoundingClientRect();
+    const x = boundingRect.x + 5;
+    const y = boundingRect.y + 5;
+    UIHelper.doubleClickAtThenDragTo(x, y, x + boundingRect.width/2, y);
+}
+
+function copyPaste() {
+    document.execCommand('copy');
+    document.execCommand('paste');
+}
+
+var offsetAfterLineBreak = 6;
+shouldBe("selectFirstLineIncludingLineBreak(); copyPaste(); textarea.selectionEnd", "offsetAfterLineBreak");
+
+</script>
+</body>
+</html>
index 06d6cf5..fc6d370 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 88: The download attribute on anchor was ignored because its href URL has a different security origin.
+CONSOLE MESSAGE: line 107: The download attribute on anchor was ignored because its href URL has a different security origin.
 Tests that the download attribute is ignored if the link is cross origin.
 
 It should navigate the subframe instead of downloading the file.
index 8234e2a..cad5d12 100644 (file)
@@ -11,6 +11,7 @@ displaylists [ Pass ]
 editing/mac [ Pass ]
 fast/scrolling/latching [ Pass ]
 media/mac [ Pass ]
+editing/pasteboard/mac [ Pass ]
 
 fast/forms/search/search-padding-cancel-results-buttons.html [ Pass ]
 fast/forms/search/search-results-hidden-crash.html [ Pass ]
index 5b320bc..fe546a8 100644 (file)
@@ -10,6 +10,25 @@ window.UIHelper = class UIHelper {
         return window.testRunner.isWebKit2;
     }
 
+    static doubleClickAt(x, y)
+    {
+        eventSender.mouseMoveTo(x, y);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+
+    static doubleClickAtThenDragTo(x1, y1, x2, y2)
+    {
+        eventSender.mouseMoveTo(x1, y1);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+        eventSender.mouseDown();
+        eventSender.mouseMoveTo(x2, y2);
+        eventSender.mouseUp();
+    }
+
     static tapAt(x, y)
     {
         console.assert(this.isIOS());
@@ -104,6 +123,22 @@ window.UIHelper = class UIHelper {
         return UIHelper.activateAt(x, y);
     }
 
+    static async selectWordByDoubleTapOrClick(element, relativeX = 5, relativeY = 5)
+    {
+        const boundingRect = element.getBoundingClientRect();
+        const x = boundingRect.x + relativeX;
+        const y = boundingRect.y + relativeY;
+        if (this.isIOS()) {
+            await UIHelper.tapAt(x, y);
+            await UIHelper.doubleTapAt(x, y);
+            // This is only here to deal with async/sync copy/paste calls, so
+            // once <rdar://problem/16207002> is resolved, should be able to remove for faster tests.
+            await new Promise(resolve => testRunner.runUIScript("uiController.uiScriptComplete()", resolve));
+        } else {
+            await UIHelper.doubleClickAt(x, y);
+        }
+    }
+
     static keyDown(key, modifiers=[])
     {
         if (!this.isWebKit2() || !this.isIOS()) {
index fbd56ce..14b8d26 100644 (file)
@@ -1,3 +1,18 @@
+2019-01-31  Megan Gardner  <megan_gardner@apple.com>
+
+        Don't insert spaces at the beginning of a newline when using smart-copy-paste
+        https://bugs.webkit.org/show_bug.cgi?id=194070
+
+        Reviewed by Tim Horton.
+
+        If our inserted content end is at the beginning of a paragraph, do not insert a space.
+        Also, if our inserted content beginning is at the end of a paragraph, do not insert a space.
+
+        Test: editing/pasteboard/mac/copy-smartpaste-first-line-in-textarea.html
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):
+
 2019-01-31  Justin Fan  <justin_fan@apple.com>
 
         [WebGPU] Build fix: disable MTLCopyAllDevices call on non-Mac platforms
index f8239d2..47d60db 100644 (file)
@@ -1344,7 +1344,7 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
         endOffset = endUpstream.offsetInContainerNode();
     }
 
-    bool needsTrailingSpace = !isEndOfParagraph(endOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(endOfInsertedContent.characterAfter(), false);
+    bool needsTrailingSpace = !isEndOfParagraph(endOfInsertedContent) && !isStartOfParagraph(endOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(endOfInsertedContent.characterAfter(), false);
     if (needsTrailingSpace && endNode) {
         bool collapseWhiteSpace = !endNode->renderer() || endNode->renderer()->style().collapseWhiteSpace();
         if (is<Text>(*endNode)) {
@@ -1368,7 +1368,7 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
         startOffset = startDownstream.offsetInContainerNode();
     }
 
-    bool needsLeadingSpace = !isStartOfParagraph(startOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(startOfInsertedContent.previous().characterAfter(), true);
+    bool needsLeadingSpace = !isStartOfParagraph(startOfInsertedContent) && !isEndOfParagraph(startOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(startOfInsertedContent.previous().characterAfter(), true);
     if (needsLeadingSpace && startNode) {
         bool collapseWhiteSpace = !startNode->renderer() || startNode->renderer()->style().collapseWhiteSpace();
         if (is<Text>(*startNode)) {