[evolution] I#1197 - Composer: BACKSPACE key on empty line simulates DEL key



commit f24cd2a8cfda9b4e146e6b181ed9021a90b207ea
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 3 10:36:15 2020 +0100

    I#1197 - Composer: BACKSPACE key on empty line simulates DEL key
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1197

 data/webkit/e-editor.js                  |  34 +++++-
 src/e-util/test-html-editor-units-bugs.c | 182 +++++++++++++++++++++++++++++++
 2 files changed, 212 insertions(+), 4 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 0bdffb07c4..e682540049 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -3174,16 +3174,42 @@ EvoEditor.beforeInputCb = function(inputEvent)
                        EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_EVENT, inputEvent.inputType, 
selection.anchorNode, selection.anchorNode,
                                EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML | 
EvoEditor.CLAIM_CONTENT_FLAG_USE_PARENT_BLOCK_NODE);
                        try {
-                               var next = selection.anchorNode.nextSibling;
+                               var next, offset = 0;
 
-                               if (!next)
+                               if (inputEvent.inputType == "deleteContentBackward") {
                                        next = selection.anchorNode.previousSibling;
-                               if (!next)
+                                       if (next) {
+                                               while (next.lastChild) {
+                                                       next = next.lastChild;
+                                               }
+
+                                               if (next.nodeType == next.TEXT_NODE)
+                                                       offset = next.nodeValue.length;
+
+                                       } else {
+                                               next = selection.anchorNode.nextSibling;
+                                       }
+                               } else {
+                                       next = selection.anchorNode.nextSibling;
+                                       if (!next)
+                                               next = selection.anchorNode.previousSibling;
+                               }
+
+                               if (!next) {
                                        next = selection.anchorNode.parentElement;
+                                       if (next && inputEvent.inputType == "deleteContentBackward") {
+                                               while (next.lastChild) {
+                                                       next = next.lastChild;
+                                               }
+
+                                               if (next.nodeType == next.TEXT_NODE)
+                                                       offset = next.nodeValue.length;
+                                       }
+                               }
 
                                selection.anchorNode.remove();
 
-                               selection.setPosition(next, 0);
+                               selection.setPosition(next, offset);
                        } finally {
                                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_EVENT, inputEvent.inputType);
                        }
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 8ca3e532d5..15196b327d 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -1788,6 +1788,187 @@ test_issue_783 (TestFixture *fixture)
        }
 }
 
+static void
+test_issue_1197 (TestFixture *fixture)
+{
+       if (!test_utils_run_simple_test (fixture,
+               "mode:plain\n"
+               "type:a\\n\\n\\n\\nb\n"
+               "seq:uub\n"
+               "type:c\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">a</div>"
+               "<div style=\"width: 71ch;\">c</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">b</div>"
+               HTML_SUFFIX,
+               "a\n"
+               "c\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:b\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">a</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">b</div>"
+               HTML_SUFFIX,
+               "a\n"
+               "\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:b\n"
+               "type:d\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">ad</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">b</div>"
+               HTML_SUFFIX,
+               "ad\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:bnn\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">a</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">b</div>"
+               HTML_SUFFIX,
+               "a\n"
+               "\n"
+               "\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "type:e\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">a</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">e</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">b</div>"
+               HTML_SUFFIX,
+               "a\n"
+               "\n"
+               "e\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:lDD\n"
+               "type:f\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">a</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">f</div>"
+               "<div style=\"width: 71ch;\">b</div>"
+               HTML_SUFFIX,
+               "a\n"
+               "\n"
+               "f\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:bD\n"
+               "type:g\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">a</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">gb</div>"
+               HTML_SUFFIX,
+               "a\n"
+               "\n"
+               "gb\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:bunnuuue\n"
+               "mode:html\n"
+               "type: \n"
+               "action:bold\n"
+               "type:bold\n"
+               "action:bold\n"
+               "type: hh\n"
+               "seq:dd",
+               HTML_PREFIX
+               "<div>a <b>bold</b> hh</div>"
+               "<div><br></div>"
+               "<div><br></div>"
+               "<div><br></div>"
+               "<div>b</div>"
+               HTML_SUFFIX,
+               "a bold hh\n"
+               "\n"
+               "\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "type:i\n",
+               HTML_PREFIX
+               "<div>a <b>bold</b> hh</div>"
+               "<div><br></div>"
+               "<div>i</div>"
+               "<div><br></div>"
+               "<div>b</div>"
+               HTML_SUFFIX,
+               "a bold hh\n"
+               "\n"
+               "i\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:bbb\n"
+               "type:j\n",
+               HTML_PREFIX
+               "<div>a <b>bold</b> hhj</div>"
+               "<div><br></div>"
+               "<div>b</div>"
+               HTML_SUFFIX,
+               "a bold hhj\n"
+               "\n"
+               "b\n")) {
+               g_test_fail ();
+               return;
+       }
+}
+
 void
 test_add_html_editor_bug_tests (void)
 {
@@ -1822,4 +2003,5 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/issue/107", test_issue_107);
        test_utils_add_test ("/issue/884", test_issue_884);
        test_utils_add_test ("/issue/783", test_issue_783);
+       test_utils_add_test ("/issue/1197", test_issue_1197);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]