Bug 426246 - cmd_deleteToBeginningOfLine should delete to the beginning of the line, not the whole line. r=masayuki
authorMarkus Stange <mstange@themasta.com>
Thu, 14 Jun 2018 15:42:16 -0400
changeset 479398 2887cf2355af0c7e5870ecce8ef022118557c1b9
parent 479397 c1a45c216af9fd8f7b8823ad5acde9c2c56b0e82
child 479399 7a6d20e982832372a931da68f9b16063901735e2
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs426246
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 426246 - cmd_deleteToBeginningOfLine should delete to the beginning of the line, not the whole line. r=masayuki MozReview-Commit-ID: 3OTOSz8u9Co
editor/libeditor/TextEditor.cpp
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug426246.html
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -611,18 +611,16 @@ TextEditor::ExtendSelectionForDelete(Sel
             if (NS_WARN_IF(NS_FAILED(rv))) {
               return rv;
             }
           }
         }
         return NS_OK;
       }
       case eToBeginningOfLine: {
-        // Try to move to end
-        selCont->IntraLineMove(true, false);
         // Select to beginning
         nsresult rv = selCont->IntraLineMove(false, true);
         *aAction = eNone;
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
         return NS_OK;
       }
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -41,16 +41,17 @@ skip-if = toolkit == 'android'
 [test_bug408231.html]
 skip-if = toolkit == 'android'
 [test_bug410986.html]
 subsuite = clipboard
 skip-if = toolkit == 'android'
 [test_bug414526.html]
 [test_bug417418.html]
 skip-if = android_version == '18' # bug 1147989
+[test_bug426246.html]
 [test_bug430392.html]
 [test_bug432225.html]
 skip-if = toolkit == 'android'
 [test_bug439808.html]
 [test_bug442186.html]
 [test_bug449243.html]
 [test_bug455992.html]
 [test_bug456244.html]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug426246.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=426246
+-->
+<html>
+<head>
+  <title>Test for Bug 426246</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=426246">Mozilla Bug 426246</a>
+<p id="display"></p>
+<div id="content" style="display: none;">
+
+</div>
+
+<div contenteditable="true" id="contenteditable1">
+  <p>first line</p>
+  <p>this is the second line</p>
+</div>
+
+<div contenteditable="true" id="contenteditable2">first line<br>this is the second line</div>
+<div contenteditable="true" id="contenteditable3"><ul><li>first line</li><li>this is the second line</li></ul></div>
+<pre contenteditable="true" id="contenteditable4">first line
+this is the second line</pre>
+
+<pre id="test">
+
+<script class="testbody" type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+  let elm1 = document.getElementById("contenteditable1");
+  elm1.focus();
+  window.getSelection().collapse(elm1.lastElementChild.firstChild, "this is the ".length);
+  SpecialPowers.doCommand(window, "cmd_deleteToBeginningOfLine");
+  is(elm1.firstElementChild.textContent, "first line", "two paragraphs: the first line should stay untouched");
+  is(elm1.lastElementChild.textContent, "second line", "two paragraphs: the characters after the caret should remain");
+
+  let elm2 = document.getElementById("contenteditable2");
+  elm2.focus();
+  window.getSelection().collapse(elm2.lastChild, "this is the ".length);
+  is(elm2.lastChild.textContent, "this is the second line", "br: correct initial content");
+  SpecialPowers.doCommand(window, "cmd_deleteToBeginningOfLine");
+  is(elm2.firstChild.textContent, "first line", "br: the first line should stay untouched");
+  is(elm2.lastChild.textContent, "second line", "br: the characters after the caret should remain");
+
+  let elm3 = document.getElementById("contenteditable3");
+  elm3.focus();
+  let firstLineLI = elm3.querySelector("li:first-child");
+  let secondLineLI = elm3.querySelector("li:last-child");
+  window.getSelection().collapse(secondLineLI.firstChild, "this is the ".length);
+  is(secondLineLI.textContent, "this is the second line", "li: correct initial content");
+  SpecialPowers.doCommand(window, "cmd_deleteToBeginningOfLine");
+  is(firstLineLI.textContent, "first line", "li: the first line should stay untouched");
+  is(secondLineLI.textContent, "second line", "li: the characters after the caret should remain");
+
+  let elm4 = document.getElementById("contenteditable4");
+  elm4.focus();
+  window.getSelection().collapse(elm4.firstChild, "first line\nthis is the ".length);
+  is(elm4.textContent, "first line\nthis is the second line", "pre: correct initial content");
+  SpecialPowers.doCommand(window, "cmd_deleteToBeginningOfLine");
+  is(elm4.textContent, "first line\nsecond line", "pre: the first line should stay untouched and the characters after the caret in the second line should remain");
+
+  SimpleTest.finish();
+});
+</script>
+</pre>
+</body>
+</html>