Text selected with double-click gets unselected after DOM modification
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Oct 2013 08:38:22 +0000 (08:38 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Oct 2013 08:38:22 +0000 (08:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=114227

Patch by Santosh Mahto <santosh.ma@samsung.com> on 2013-10-29
Reviewed by Ryosuke Niwa.

Source/WebCore:

Before this patch when selection is done by double-click (start and base remain
same) and DOM is modified then selection gets vanished. This does not
happen when selection is done by dragging mouse. This happens because
on double-click base and extent remain the same and on DOM
modification we update the selection with base and extent, so we loose
the selection. Since in double-click case start/end contain the
correct selection, same should be used after dom modification to
update selection.

Test: editing/selection/double-click-selection-with-dom-mutation.html

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::textWasReplaced): use start/end to update
selection in case double click selection. Added a check for base !=
extent, if base != extent use base/extent to update the selection
otherwise use start/end with directionality check.

LayoutTests:

New Testcase to test that selection remain intact when selection is
created by double-click and then dom is modified.

* editing/selection/double-click-selection-with-dom-mutation-expected.txt: Added.
* editing/selection/double-click-selection-with-dom-mutation.html: Added.

Rebaselined the below test cases.
* platform/mac/editing/deleting/smart-delete-003-expected.txt:
* platform/mac/editing/deleting/smart-delete-004-expected.txt:

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

LayoutTests/ChangeLog
LayoutTests/editing/selection/double-click-selection-with-dom-mutation-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/double-click-selection-with-dom-mutation.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/deleting/smart-delete-003-expected.txt
LayoutTests/platform/mac/editing/deleting/smart-delete-004-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/editing/FrameSelection.cpp

index 18bb636..7e0c37e 100644 (file)
@@ -1,3 +1,20 @@
+2013-10-29  Santosh Mahto  <santosh.ma@samsung.com>
+
+        Text selected with double-click gets unselected after DOM modification
+        https://bugs.webkit.org/show_bug.cgi?id=114227
+
+        Reviewed by Ryosuke Niwa.
+
+        New Testcase to test that selection remain intact when selection is
+        created by double-click and then dom is modified.
+
+        * editing/selection/double-click-selection-with-dom-mutation-expected.txt: Added.
+        * editing/selection/double-click-selection-with-dom-mutation.html: Added.
+
+        Rebaselined the below test cases.
+        * platform/mac/editing/deleting/smart-delete-003-expected.txt:
+        * platform/mac/editing/deleting/smart-delete-004-expected.txt:
+
 2013-10-29  Mihnea Ovidenie  <mihnea@adobe.com>
 
         [CSSRegions] Display anonymous regions in DRT
diff --git a/LayoutTests/editing/selection/double-click-selection-with-dom-mutation-expected.txt b/LayoutTests/editing/selection/double-click-selection-with-dom-mutation-expected.txt
new file mode 100644 (file)
index 0000000..50ac8c9
--- /dev/null
@@ -0,0 +1,17 @@
+This test is for bug where selection vanishes when selection is created by Double-Click on text and then DOM is modified. Expected Output is that selected text should remain selected
+
+Before::
+| "Double-click to select "
+| <span>
+|   id="target"
+|   "→this←"
+| " text."
+
+After::
+| "Double-click to select "
+| <span>
+|   id="target"
+|   "→"
+|   "<#selection-anchor>this<#selection-focus>"
+|   "←"
+| " text."
diff --git a/LayoutTests/editing/selection/double-click-selection-with-dom-mutation.html b/LayoutTests/editing/selection/double-click-selection-with-dom-mutation.html
new file mode 100644 (file)
index 0000000..f7c3dd4
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <script src="../editing.js"></script>
+    <script src="../../resources/dump-as-markup.js"></script>
+</head>
+<body>
+<p id="container">Double-click to select <span id="target">→this←</span> text.</p>
+
+<script>
+    Markup.description('This test is for bug where selection vanishes when selection is created by Double-Click on text and then DOM is modified. Expected Output is that selected text should remain selected');
+    var target = document.getElementById("target");
+    Markup.dump("container", 'Before:');
+    doubleClick(target.offsetLeft + target.offsetWidth / 2, target.offsetTop + target.offsetHeight / 2);
+    var domRange = getSelection().getRangeAt(0);
+
+    function splitTextOnBoundary(container, offset, workaroundPreserveEnd) {
+        if (offset && offset < container.length) {
+            // WORKAROUND: doing the split manually avoids https://bugs.webkit.org/show_bug.cgi?id=114041
+            var newNode = document.createTextNode('');
+            if (workaroundPreserveEnd) {
+                newNode.data = container.data.slice(0, offset);
+                container.deleteData(0, offset);
+                container.parentNode.insertBefore(newNode, container);
+            } else {
+                newNode.data = container.data.slice(offset);
+                container.deleteData(offset, container.data.length);
+                container.parentNode.insertBefore(newNode, container.nextSibling);
+            }
+        }
+    }
+    splitTextOnBoundary(domRange.startContainer, domRange.startOffset, true);
+    splitTextOnBoundary(domRange.endContainer, domRange.endOffset, false);
+
+    Markup.dump("container", 'After:');
+</script>
+</body>
+</html>
index ab8dd3c..ebe381d 100644 (file)
@@ -7,6 +7,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: shouldDeleteDOMRange:range from 4 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of #text > DIV > BODY > HTML > #document to 0 of #text > DIV > BODY > HTML > #document toDOMRange:range from 3 of #text > DIV > BODY > HTML > #document to 3 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
index fe7b03f..f998451 100644 (file)
@@ -7,6 +7,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: shouldDeleteDOMRange:range from 4 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of #text > DIV > BODY > HTML > #document to 0 of #text > DIV > BODY > HTML > #document toDOMRange:range from 3 of #text > DIV > BODY > HTML > #document to 3 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
index f05c8f6..1cf751a 100644 (file)
@@ -1,3 +1,27 @@
+2013-10-29  Santosh Mahto  <santosh.ma@samsung.com>
+
+        Text selected with double-click gets unselected after DOM modification
+        https://bugs.webkit.org/show_bug.cgi?id=114227
+
+        Reviewed by Ryosuke Niwa.
+
+        Before this patch when selection is done by double-click (start and base remain
+        same) and DOM is modified then selection gets vanished. This does not
+        happen when selection is done by dragging mouse. This happens because
+        on double-click base and extent remain the same and on DOM
+        modification we update the selection with base and extent, so we loose
+        the selection. Since in double-click case start/end contain the
+        correct selection, same should be used after dom modification to
+        update selection.
+
+        Test: editing/selection/double-click-selection-with-dom-mutation.html
+
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::textWasReplaced): use start/end to update
+        selection in case double click selection. Added a check for base !=
+        extent, if base != extent use base/extent to update the selection
+        otherwise use start/end with directionality check.
+
 2013-10-29  Mihnea Ovidenie  <mihnea@adobe.com>
 
         [CSSRegions] Display anonymous regions in DRT
index 93b69de..be65f6f 100644 (file)
@@ -460,7 +460,13 @@ void FrameSelection::textWasReplaced(CharacterData* node, unsigned offset, unsig
 
     if (base != m_selection.base() || extent != m_selection.extent() || start != m_selection.start() || end != m_selection.end()) {
         VisibleSelection newSelection;
-        newSelection.setWithoutValidation(base, extent);
+        if (base != extent)
+            newSelection.setWithoutValidation(base, extent);
+        else if (m_selection.isDirectional() && !m_selection.isBaseFirst())
+            newSelection.setWithoutValidation(end, start);
+        else
+            newSelection.setWithoutValidation(start, end);
+
         m_frame->document()->updateLayout();
         setSelection(newSelection, DoNotSetFocus);
     }