Smart link can erroneously move caret after an URL when typing immediately before it
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2013 19:44:37 +0000 (19:44 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2013 19:44:37 +0000 (19:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=92812

Reviewed by Enrica Casucci.

Source/WebCore:

The bug was caused by smart link being triggered even when a user finished typing a word
immediately before an URL. We already had a logic to avoid smart-linking an URL when the caret
was after the URL but we were missing a check for when the caret is before the URL.

Fixed the bug by adding this check.

Test: editing/inserting/smart-link-when-caret-is-moved-before-URL.html

* editing/Editor.cpp:
(WebCore::Editor::markAndReplaceFor):

LayoutTests:

Add a regression for typing immediately before an URL while smart link is enabled.
WebKit should not be moving the caret erroneously.

* editing/inserting/smart-link-when-caret-is-moved-before-URL-expected.txt: Added.
* editing/inserting/smart-link-when-caret-is-moved-before-URL.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/inserting/smart-link-when-caret-is-moved-before-URL-expected.txt [new file with mode: 0644]
LayoutTests/editing/inserting/smart-link-when-caret-is-moved-before-URL.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp

index 725df7445d573913353f80157e331b9123867aef..a5e5c340fea33deac86c2700dc1542d87a742711 100644 (file)
@@ -1,3 +1,16 @@
+2013-02-01  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Smart link can erroneously move caret after an URL when typing immediately before it
+        https://bugs.webkit.org/show_bug.cgi?id=92812
+
+        Reviewed by Enrica Casucci.
+
+        Add a regression for typing immediately before an URL while smart link is enabled.
+        WebKit should not be moving the caret erroneously.
+
+        * editing/inserting/smart-link-when-caret-is-moved-before-URL-expected.txt: Added.
+        * editing/inserting/smart-link-when-caret-is-moved-before-URL.html: Added.
+
 2013-02-01  Julien Chaffraix  <jchaffraix@webkit.org>
 
         [CSS Grid Layout] computePreferredLogicalWidths doesn't handle minmax tracks
diff --git a/LayoutTests/editing/inserting/smart-link-when-caret-is-moved-before-URL-expected.txt b/LayoutTests/editing/inserting/smart-link-when-caret-is-moved-before-URL-expected.txt
new file mode 100644 (file)
index 0000000..51cc052
--- /dev/null
@@ -0,0 +1,10 @@
+This test demonstrates that smart link doesn't erroneously trigger when the user moves the caret immediately before an URL.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+To manually run this test, disable "Check Spelling While Typing" and enable "Smart Link". The caret should be shown immediately after "zz" below:
+
+PASS editor.selectionStart is 3
+PASS editor.selectionEnd is 3
+
diff --git a/LayoutTests/editing/inserting/smart-link-when-caret-is-moved-before-URL.html b/LayoutTests/editing/inserting/smart-link-when-caret-is-moved-before-URL.html
new file mode 100644 (file)
index 0000000..78a0ecc
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<body>
+<textarea id="editor" cols="50" rows="5">
+</textarea>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script>
+
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setAutomaticLinkDetectionEnabled(true);
+}
+
+description('This test demonstrates that smart link doesn\'t erroneously trigger when the user moves the caret immediately before an URL.');
+
+debug('To manually run this test, disable "Check Spelling While Typing" and enable "Smart Link". The caret should be shown immediately after "zz" below:');
+debug('');
+
+var editor = document.getElementById('editor');
+editor.focus();
+document.execCommand('InsertText', false, 'http://webkit.org/');
+getSelection().modify('move', 'backward', 'lineBoundary');
+document.execCommand('InsertText', false, 'zz');
+document.execCommand('InsertText', false, ' ');
+
+shouldBe('editor.selectionStart', '3');
+shouldBe('editor.selectionEnd', '3');
+
+editor.style.display = 'none';
+
+</script>
+</body>
+</html>
index 20c748d291d565e9db9a311968516a2e69bf1352..7a937b9b6c8d151764e603e1023f0d7a4ebed5a2 100644 (file)
@@ -1,3 +1,21 @@
+2013-02-01  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Smart link can erroneously move caret after an URL when typing immediately before it
+        https://bugs.webkit.org/show_bug.cgi?id=92812
+
+        Reviewed by Enrica Casucci.
+
+        The bug was caused by smart link being triggered even when a user finished typing a word
+        immediately before an URL. We already had a logic to avoid smart-linking an URL when the caret
+        was after the URL but we were missing a check for when the caret is before the URL.
+
+        Fixed the bug by adding this check.
+
+        Test: editing/inserting/smart-link-when-caret-is-moved-before-URL.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::markAndReplaceFor):
+
 2013-02-01  Roger Fong  <roger_fong@apple.com>
 
         Unreviewed. Windows build fix. FloatSize.cpp was not included in the project.
index fb82f0fce7965e03854a1140086bb54ac02ff8c1..ba6f60fd16f04fadcf018fc9a57d1359f6025f3c 100644 (file)
@@ -2137,7 +2137,9 @@ void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect
             VisibleSelection selectionToReplace(rangeToReplace.get(), DOWNSTREAM);
 
             // adding links should be done only immediately after they are typed
-            if (result->type == TextCheckingTypeLink && selectionOffset > resultLocation + resultLength + 1)
+            int resultEnd = resultLocation + resultLength;
+            if (result->type == TextCheckingTypeLink
+                && (selectionOffset > resultEnd + 1 || selectionOffset <= resultLocation))
                 continue;
 
             if (!(shouldPerformReplacement || shouldCheckForCorrection || shouldMarkLink) || !doReplacement)