- Revision
- 158186
- Author
- [email protected]
- Date
- 2013-10-29 01:38:22 -0700 (Tue, 29 Oct 2013)
Log Message
Text selected with double-click gets unselected after DOM modification
https://bugs.webkit.org/show_bug.cgi?id=114227
Patch by Santosh Mahto <[email protected]> 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:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (158185 => 158186)
--- trunk/LayoutTests/ChangeLog 2013-10-29 08:34:18 UTC (rev 158185)
+++ trunk/LayoutTests/ChangeLog 2013-10-29 08:38:22 UTC (rev 158186)
@@ -1,3 +1,20 @@
+2013-10-29 Santosh Mahto <[email protected]>
+
+ 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 <[email protected]>
[CSSRegions] Display anonymous regions in DRT
Added: trunk/LayoutTests/editing/selection/double-click-selection-with-dom-mutation-expected.txt (0 => 158186)
--- trunk/LayoutTests/editing/selection/double-click-selection-with-dom-mutation-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/selection/double-click-selection-with-dom-mutation-expected.txt 2013-10-29 08:38:22 UTC (rev 158186)
@@ -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."
Added: trunk/LayoutTests/editing/selection/double-click-selection-with-dom-mutation.html (0 => 158186)
--- trunk/LayoutTests/editing/selection/double-click-selection-with-dom-mutation.html (rev 0)
+++ trunk/LayoutTests/editing/selection/double-click-selection-with-dom-mutation.html 2013-10-29 08:38:22 UTC (rev 158186)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <script src=""
+ <script src=""
+</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 = "" offset);
+ container.deleteData(0, offset);
+ container.parentNode.insertBefore(newNode, container);
+ } else {
+ newNode.data = ""
+ 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>
Modified: trunk/LayoutTests/platform/mac/editing/deleting/smart-delete-003-expected.txt (158185 => 158186)
--- trunk/LayoutTests/platform/mac/editing/deleting/smart-delete-003-expected.txt 2013-10-29 08:34:18 UTC (rev 158185)
+++ trunk/LayoutTests/platform/mac/editing/deleting/smart-delete-003-expected.txt 2013-10-29 08:38:22 UTC (rev 158186)
@@ -7,6 +7,8 @@
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
Modified: trunk/LayoutTests/platform/mac/editing/deleting/smart-delete-004-expected.txt (158185 => 158186)
--- trunk/LayoutTests/platform/mac/editing/deleting/smart-delete-004-expected.txt 2013-10-29 08:34:18 UTC (rev 158185)
+++ trunk/LayoutTests/platform/mac/editing/deleting/smart-delete-004-expected.txt 2013-10-29 08:38:22 UTC (rev 158186)
@@ -7,6 +7,8 @@
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
Modified: trunk/Source/WebCore/ChangeLog (158185 => 158186)
--- trunk/Source/WebCore/ChangeLog 2013-10-29 08:34:18 UTC (rev 158185)
+++ trunk/Source/WebCore/ChangeLog 2013-10-29 08:38:22 UTC (rev 158186)
@@ -1,3 +1,27 @@
+2013-10-29 Santosh Mahto <[email protected]>
+
+ 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 <[email protected]>
[CSSRegions] Display anonymous regions in DRT
Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (158185 => 158186)
--- trunk/Source/WebCore/editing/FrameSelection.cpp 2013-10-29 08:34:18 UTC (rev 158185)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp 2013-10-29 08:38:22 UTC (rev 158186)
@@ -460,7 +460,13 @@
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);
}