[evolution] I#1398 - Composer: Fails to delete column/row of a table



commit 01d596cae40afbd2129e277b590fee0179a927fd
Author: Milan Crha <mcrha redhat com>
Date:   Mon Mar 1 15:20:05 2021 +0100

    I#1398 - Composer: Fails to delete column/row of a table
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1398

 data/webkit/e-editor.js                     | 22 ++++++++++++
 src/modules/webkit-editor/e-webkit-editor.c | 56 +++++++++++++++++++----------
 2 files changed, 60 insertions(+), 18 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 74ba6f413a..c618c53d31 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -3747,6 +3747,22 @@ EvoEditor.setCurrentElement = function(element)
                element.setAttribute(EvoEditor.CURRENT_ELEMENT_ATTR, "1");
 }
 
+// selects element of tag name 'tagName'; being it "TABLE*", then nearest TABLE-related element
+EvoEditor.DialogUtilsCurrentElementFromFocus = function(tagName)
+{
+       var node = document.getSelection().focusNode;
+       var anyInTable = tagName == "TABLE*";
+
+       while (node && node.tagName != "BODY") {
+               if (node.tagName == tagName || (anyInTable && (node.tagName == "TH" || node.tagName == "TR" 
|| node.tagName == "TD"))) {
+                       EvoEditor.setCurrentElement(node);
+                       break;
+               }
+
+               node = node.parentElement;
+       }
+}
+
 EvoEditor.OnDialogOpen = function(name)
 {
        EvoEditor.propertiesSelection = null;
@@ -4538,7 +4554,13 @@ EvoEditor.DialogUtilsTableDelete = function()
        EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "TableDelete", element, element,
                EvoEditor.CLAIM_CONTENT_FLAG_USE_PARENT_BLOCK_NODE | EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML);
        try {
+               var parent = element.parentElement;
+
                element.remove();
+
+               if (EvoEditor.isEmptyParagraph(parent) && !parent.firstChild) {
+                       parent.appendChild(document.createElement("BR"));
+               }
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "TableDelete");
                EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 894c3fd671..85d4fe6de2 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -2926,7 +2926,11 @@ webkit_editor_delete_cell_contents (EContentEditor *editor)
        EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
 
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableDeleteCellContent();");
+               "var arr = EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.DialogUtilsCurrentElementFromFocus(\"TABLE*\");"
+               "EvoEditor.DialogUtilsTableDeleteCellContent();"
+               "EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.RestoreCurrentElementAttr(arr);");
 }
 
 static void
@@ -2935,7 +2939,11 @@ webkit_editor_delete_column (EContentEditor *editor)
        EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
 
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableDeleteColumn();");
+               "var arr = EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.DialogUtilsCurrentElementFromFocus(\"TABLE*\");"
+               "EvoEditor.DialogUtilsTableDeleteColumn();"
+               "EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.RestoreCurrentElementAttr(arr);");
 }
 
 static void
@@ -2944,7 +2952,11 @@ webkit_editor_delete_row (EContentEditor *editor)
        EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
 
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableDeleteRow();");
+               "var arr = EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.DialogUtilsCurrentElementFromFocus(\"TABLE*\");"
+               "EvoEditor.DialogUtilsTableDeleteRow();"
+               "EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.RestoreCurrentElementAttr(arr);");
 }
 
 static void
@@ -2953,43 +2965,51 @@ webkit_editor_delete_table (EContentEditor *editor)
        EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
 
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableDelete();");
+               "var arr = EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.DialogUtilsCurrentElementFromFocus(\"TABLE*\");"
+               "EvoEditor.DialogUtilsTableDelete();"
+               "EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.RestoreCurrentElementAttr(arr);");
 }
 
 static void
-webkit_editor_insert_column_after (EContentEditor *editor)
+webikt_editor_call_table_insert (EContentEditor *editor,
+                                const gchar *what,
+                                gint where)
 {
        EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
 
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableInsert(%s, %d);", "column", +1);
+               "var arr = EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.DialogUtilsCurrentElementFromFocus(\"TABLE*\");"
+               "EvoEditor.DialogUtilsTableInsert(%s, %d);"
+               "EvoEditor.RemoveCurrentElementAttr();"
+               "EvoEditor.RestoreCurrentElementAttr(arr);",
+               what, where);
 }
 
 static void
-webkit_editor_insert_column_before (EContentEditor *editor)
+webkit_editor_insert_column_after (EContentEditor *editor)
 {
-       EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
+       webikt_editor_call_table_insert (editor, "column", +1);
+}
 
-       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableInsert(%s, %d);", "column", -1);
+static void
+webkit_editor_insert_column_before (EContentEditor *editor)
+{
+       webikt_editor_call_table_insert (editor, "column", -1);
 }
 
 static void
 webkit_editor_insert_row_above (EContentEditor *editor)
 {
-       EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
-
-       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableInsert(%s, %d);", "row", -1);
+       webikt_editor_call_table_insert (editor, "row", -1);
 }
 
 static void
 webkit_editor_insert_row_below (EContentEditor *editor)
 {
-       EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
-
-       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
-               "EvoEditor.DialogUtilsTableInsert(%s, %d);", "row", +1);
+       webikt_editor_call_table_insert (editor, "row", +1);
 }
 
 static void


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