Title: [181465] trunk
- Revision
- 181465
- Author
- [email protected]
- Date
- 2015-03-12 17:57:10 -0700 (Thu, 12 Mar 2015)
Log Message
REGRESSION(r180726): Removing an empty line at the end of textarea clears the entire texture
https://bugs.webkit.org/show_bug.cgi?id=142646
Reviewed by Darin Adler.
Source/WebCore:
The bug was caused by TypingCommand::deleteKeyPressed erroneously determining the editable root to be empty because
Position::atStartOfTree returns true when it's anchored at a BR that is immediately below the root editable element.
Fixed the bug by replacing the use of the deprecated atFirstEditingPositionForNode by a code that understands modern
position types such as PositionIsBeforeAnchor in atStartOfTree and atEndOfTree. These two functions will no longer
return true when anchored before or after BR after this patch.
Test: editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html
* dom/Position.cpp:
(WebCore::Position::atStartOfTree):
(WebCore::Position::atEndOfTree):
LayoutTests:
Added a regression test for deleting empty lines at the end of a textarea element.
* editing/deleting/delete-empty-line-breaks-at-end-of-textarea-expected.txt: Added.
* editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (181464 => 181465)
--- trunk/LayoutTests/ChangeLog 2015-03-13 00:55:09 UTC (rev 181464)
+++ trunk/LayoutTests/ChangeLog 2015-03-13 00:57:10 UTC (rev 181465)
@@ -1,3 +1,15 @@
+2015-03-12 Ryosuke Niwa <[email protected]>
+
+ REGRESSION(r180726): Removing an empty line at the end of textarea clears the entire texture
+ https://bugs.webkit.org/show_bug.cgi?id=142646
+
+ Reviewed by Darin Adler.
+
+ Added a regression test for deleting empty lines at the end of a textarea element.
+
+ * editing/deleting/delete-empty-line-breaks-at-end-of-textarea-expected.txt: Added.
+ * editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html: Added.
+
2015-03-12 Yusuke Suzuki <[email protected]>
Integrate MapData into JSMap and JSSet
Added: trunk/LayoutTests/editing/deleting/delete-empty-line-breaks-at-end-of-textarea-expected.txt (0 => 181465)
--- trunk/LayoutTests/editing/deleting/delete-empty-line-breaks-at-end-of-textarea-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/deleting/delete-empty-line-breaks-at-end-of-textarea-expected.txt 2015-03-13 00:57:10 UTC (rev 181465)
@@ -0,0 +1,20 @@
+This tests removing empty lines at the end of an textarea.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+textarea.focus();
+textarea.selectionStart = textarea.selectionEnd = textarea.value.length
+PASS textarea.value is "hello\n\n"
+PASS textarea.selectionStart is 7
+PASS textarea.selectionEnd is 7
+PASS document.execCommand("delete", false, null); textarea.value is "hello\n"
+PASS textarea.selectionStart is 6
+PASS textarea.selectionEnd is 6
+PASS document.execCommand("delete", false, null); textarea.value is "hello"
+PASS textarea.selectionStart is 5
+PASS textarea.selectionEnd is 5
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html (0 => 181465)
--- trunk/LayoutTests/editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html (rev 0)
+++ trunk/LayoutTests/editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html 2015-03-13 00:57:10 UTC (rev 181465)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<body>
+<textarea cols=5 rows=5>
+hello
+
+</textarea>
+<script src=""
+<script>
+
+description('This tests removing empty lines at the end of an textarea.');
+
+var textarea = document.querySelector('textarea');
+evalAndLog('textarea.focus();');
+evalAndLog('textarea.selectionStart = textarea.selectionEnd = textarea.value.length');
+shouldBe('textarea.value' ,'"hello\\n\\n"');
+shouldBe('textarea.selectionStart' ,'7');
+shouldBe('textarea.selectionEnd' ,'7');
+
+shouldBe('document.execCommand("delete", false, null); textarea.value', '"hello\\n"');
+shouldBe('textarea.selectionStart', '6');
+shouldBe('textarea.selectionEnd', '6');
+
+shouldBe('document.execCommand("delete", false, null); textarea.value', '"hello"');
+shouldBe('textarea.selectionStart', '5');
+shouldBe('textarea.selectionEnd', '5');
+
+textarea.style.display = 'none';
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (181464 => 181465)
--- trunk/Source/WebCore/ChangeLog 2015-03-13 00:55:09 UTC (rev 181464)
+++ trunk/Source/WebCore/ChangeLog 2015-03-13 00:57:10 UTC (rev 181465)
@@ -1,3 +1,23 @@
+2015-03-12 Ryosuke Niwa <[email protected]>
+
+ REGRESSION(r180726): Removing an empty line at the end of textarea clears the entire texture
+ https://bugs.webkit.org/show_bug.cgi?id=142646
+
+ Reviewed by Darin Adler.
+
+ The bug was caused by TypingCommand::deleteKeyPressed erroneously determining the editable root to be empty because
+ Position::atStartOfTree returns true when it's anchored at a BR that is immediately below the root editable element.
+
+ Fixed the bug by replacing the use of the deprecated atFirstEditingPositionForNode by a code that understands modern
+ position types such as PositionIsBeforeAnchor in atStartOfTree and atEndOfTree. These two functions will no longer
+ return true when anchored before or after BR after this patch.
+
+ Test: editing/deleting/delete-empty-line-breaks-at-end-of-textarea.html
+
+ * dom/Position.cpp:
+ (WebCore::Position::atStartOfTree):
+ (WebCore::Position::atEndOfTree):
+
2015-03-12 Yusuke Suzuki <[email protected]>
Integrate MapData into JSMap and JSSet
Modified: trunk/Source/WebCore/dom/Position.cpp (181464 => 181465)
--- trunk/Source/WebCore/dom/Position.cpp 2015-03-13 00:55:09 UTC (rev 181464)
+++ trunk/Source/WebCore/dom/Position.cpp 2015-03-13 00:57:10 UTC (rev 181465)
@@ -476,14 +476,46 @@
{
if (isNull())
return true;
- return !findParent(containerNode()) && atFirstEditingPositionForNode();
+ if (findParent(containerNode()))
+ return false;
+
+ switch (m_anchorType) {
+ case PositionIsOffsetInAnchor:
+ return m_offset <= 0;
+ case PositionIsBeforeAnchor:
+ return !m_anchorNode->previousSibling();
+ case PositionIsAfterAnchor:
+ return false;
+ case PositionIsBeforeChildren:
+ return true;
+ case PositionIsAfterChildren:
+ return !lastOffsetForEditing(m_anchorNode.get());
+ }
+ ASSERT_NOT_REACHED();
+ return false;
}
bool Position::atEndOfTree() const
{
if (isNull())
return true;
- return !findParent(containerNode()) && atLastEditingPositionForNode();
+ if (findParent(containerNode()))
+ return false;
+
+ switch (m_anchorType) {
+ case PositionIsOffsetInAnchor:
+ return m_offset >= lastOffsetForEditing(m_anchorNode.get());
+ case PositionIsBeforeAnchor:
+ return false;
+ case PositionIsAfterAnchor:
+ return !m_anchorNode->nextSibling();
+ case PositionIsBeforeChildren:
+ return !lastOffsetForEditing(m_anchorNode.get());
+ case PositionIsAfterChildren:
+ return true;
+ }
+ ASSERT_NOT_REACHED();
+ return false;
}
// return first preceding DOM position rendered at a different location, or "this"
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes