[evolution/wip/mcrha/webkit-jsc-api] webkit-editor: Various fixes for spotted bugs



commit cbdfb573e9e4df87a5a17ff74af33ad02c4f153e
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 22 14:02:47 2020 +0200

    webkit-editor: Various fixes for spotted bugs

 data/webkit/e-editor.js                     | 70 ++++++++++++++++-------------
 src/modules/webkit-editor/e-webkit-editor.c | 25 ++++++++---
 2 files changed, 56 insertions(+), 39 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 829a9ee4f5..bc1e945806 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1618,12 +1618,7 @@ EvoEditor.InsertHTML = function(opType, html)
                        node = list[ii];
 
                        EvoEditor.setAttributeWithUndoRedo("InsertHTML::fixBlockquote", node, "class", null);
-
-                       if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
-                               EvoEditor.setAttributeWithUndoRedo("InsertHTML::fixBlockquote", node, 
"style", null);
-                       } else {
-                               EvoEditor.setAttributeWithUndoRedo("InsertHTML::fixBlockquote", node, 
"style", EvoEditor.BLOCKQUOTE_STYLE);
-                       }
+                       EvoEditor.setAttributeWithUndoRedo("InsertHTML::fixBlockquote", node, "style", null);
                }
 
                EvoEditor.correctParagraphsAfterInsertContent(opType);
@@ -2102,13 +2097,8 @@ EvoEditor.convertTags = function()
        for (ii = list.length - 1; ii >= 0; ii--) {
                var blockquoteNode = list[ii];
 
-               if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
-                       blockquoteNode.removeAttribute("class");
-                       blockquoteNode.removeAttribute("style");
-               } else {
-                       blockquoteNode.removeAttribute("class");
-                       blockquoteNode.setAttribute("style", EvoEditor.BLOCKQUOTE_STYLE);
-               }
+               blockquoteNode.removeAttribute("class");
+               blockquoteNode.removeAttribute("style");
        }
 
        var node = document.body.firstChild, next;
@@ -2369,7 +2359,7 @@ EvoEditor.convertHtmlToSend = function()
        var html, bgcolor, text, link, vlink;
        var unsetBgcolor = false, unsetText = false, unsetLink = false, unsetVlink = false;
        var themeCss, inheritThemeColors = EvoEditor.inheritThemeColors;
-       var ii, styles, styleNode = null, topSignatureSpacers;
+       var ii, styles, styleNode = null, topSignatureSpacers, elems;
 
        themeCss = EvoEditor.UpdateThemeStyleSheet(null);
        bgcolor = document.documentElement.getAttribute("x-evo-bgcolor");
@@ -2420,8 +2410,24 @@ EvoEditor.convertHtmlToSend = function()
                }
        }
 
+       if (EvoEditor.mode == EvoEditor.MODE_HTML) {
+               elems = document.getElementsByTagName("BLOCKQUOTE");
+
+               for (ii = 0; ii < elems.length; ii++) {
+                       elems[ii].setAttribute("style", EvoEditor.BLOCKQUOTE_STYLE);
+               }
+       }
+
        html = document.documentElement.outerHTML;
 
+       if (EvoEditor.mode == EvoEditor.MODE_HTML) {
+               elems = document.getElementsByTagName("BLOCKQUOTE");
+
+               for (ii = 0; ii < elems.length; ii++) {
+                       elems[ii].removeAttribute("style");
+               }
+       }
+
        if (styleNode)
                styleNode.id = "x-evo-body-fontname";
 
@@ -2470,6 +2476,8 @@ EvoEditor.GetContent = function(flags, cid_uid_prefix)
        if (!document.body)
                return content_data;
 
+       var scrollX = window.scrollX, scrollY = window.scrollY;
+
        EvoUndoRedo.Disable();
 
        try {
@@ -2658,6 +2666,9 @@ EvoEditor.GetContent = function(flags, cid_uid_prefix)
                }
        }
 
+       // the above changes can cause change of the scroll offset, thus restore it
+       window.scrollTo(scrollX, scrollY);
+
        return content_data;
 }
 
@@ -4630,7 +4641,10 @@ EvoEditor.removeUnwantedTags = function(parent)
 
 EvoEditor.InsertSignature = function(content, isHTML, uid, fromMessage, checkChanged, ignoreNextChange, 
startBottom, topSignature, addDelimiter)
 {
-       var sigSpan, node;
+       var sigSpan, node, scrollX, scrollY;
+
+       scrollX = window.scrollX;
+       scrollY = window.scrollY;
 
        sigSpan = document.createElement("SPAN");
        sigSpan.className = "-x-evo-signature";
@@ -4837,6 +4851,9 @@ EvoEditor.InsertSignature = function(content, isHTML, uid, fromMessage, checkCha
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_GROUP, "InsertSignature");
        }
 
+       // the above changes can cause change of the scroll offset, thus restore it
+       window.scrollTo(scrollX, scrollY);
+
        var res = [];
 
        res["fromMessage"] = fromMessage;
@@ -4882,9 +4899,6 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
 
                if (quote) {
                        content.setAttribute("type", "cite");
-
-                       if (EvoEditor.mode != EvoEditor.MODE_PLAIN_TEXT)
-                               content.setAttribute("style", EvoEditor.BLOCKQUOTE_STYLE);
                }
 
                if (isHTML) {
@@ -5121,13 +5135,8 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
                        for (ii = 0; ii < list.length; ii++) {
                                var node = list[ii];
 
-                               if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
-                                       node.removeAttribute("class");
-                                       node.removeAttribute("style");
-                               } else {
-                                       node.removeAttribute("class");
-                                       node.setAttribute("style", EvoEditor.BLOCKQUOTE_STYLE);
-                               }
+                               node.removeAttribute("class");
+                               node.removeAttribute("style");
                        }
 
                        var selection = document.getSelection();
@@ -5399,13 +5408,8 @@ EvoEditor.processLoadedContent = function()
                        }
                }
 
-               if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
-                       blockquoteNode.removeAttribute("class");
-                       blockquoteNode.removeAttribute("style");
-               } else {
-                       blockquoteNode.removeAttribute("class");
-                       blockquoteNode.setAttribute("style", EvoEditor.BLOCKQUOTE_STYLE);
-               }
+               blockquoteNode.removeAttribute("class");
+               blockquoteNode.removeAttribute("style");
        }
 
        if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
@@ -5439,6 +5443,7 @@ EvoEditor.processLoadedContent = function()
                node.removeAttribute("id");
 
                document.getSelection().setPosition(node, 0);
+               node.scrollIntoView();
        }
 
        if (EvoEditor.START_BOTTOM) {
@@ -5449,6 +5454,7 @@ EvoEditor.processLoadedContent = function()
                EvoEditor.maybeUpdateParagraphWidth(node);
 
                document.getSelection().setPosition(node, 0);
+               node.scrollIntoView();
        }
 }
 
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 7ba13e7a00..51267f5333 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -801,7 +801,7 @@ webkit_editor_update_color_value (JSCValue *jsc_params,
 }
 
 static void webkit_editor_update_styles (EContentEditor *editor);
-static void webkit_editor_style_updated_cb (EWebKitEditor *wk_editor);
+static void webkit_editor_style_updated (EWebKitEditor *wk_editor, gboolean force);
 
 static void
 formatting_changed_cb (WebKitUserContentManager *manager,
@@ -843,7 +843,7 @@ formatting_changed_cb (WebKitUserContentManager *manager,
        if (changed) {
                /* Update fonts - in plain text we only want monospaced */
                webkit_editor_update_styles (E_CONTENT_EDITOR (wk_editor));
-               webkit_editor_style_updated_cb (wk_editor);
+               webkit_editor_style_updated (wk_editor, FALSE);
 
                g_object_notify (object, "html-mode");
        }
@@ -1844,7 +1844,8 @@ get_color_from_context (GtkStyleContext *context,
 }
 
 static void
-webkit_editor_style_updated_cb (EWebKitEditor *wk_editor)
+webkit_editor_style_updated (EWebKitEditor *wk_editor,
+                            gboolean force)
 {
        EContentEditor *cnt_editor;
        GdkRGBA bgcolor, fgcolor, link_color, vlink_color;
@@ -1892,7 +1893,8 @@ webkit_editor_style_updated_cb (EWebKitEditor *wk_editor)
        get_color_from_context (style_context, "link-color", &link_color);
        get_color_from_context (style_context, "visited-link-color", &vlink_color);
 
-       if (gdk_rgba_equal (&bgcolor, &wk_editor->priv->theme_bgcolor) &&
+       if (!force &&
+           gdk_rgba_equal (&bgcolor, &wk_editor->priv->theme_bgcolor) &&
            gdk_rgba_equal (&fgcolor, &wk_editor->priv->theme_fgcolor) &&
            gdk_rgba_equal (&link_color, &wk_editor->priv->theme_link_color) &&
            gdk_rgba_equal (&vlink_color, &wk_editor->priv->theme_vlink_color))
@@ -1927,6 +1929,12 @@ webkit_editor_style_updated_cb (EWebKitEditor *wk_editor)
        g_string_free (css, TRUE);
 }
 
+static void
+webkit_editor_style_updated_cb (EWebKitEditor *wk_editor)
+{
+       webkit_editor_style_updated (wk_editor, FALSE);
+}
+
 static gboolean
 webkit_editor_get_html_mode (EWebKitEditor *wk_editor)
 {
@@ -1978,7 +1986,7 @@ webkit_editor_set_html_mode (EWebKitEditor *wk_editor,
        }
 
        webkit_editor_update_styles (E_CONTENT_EDITOR (wk_editor));
-       webkit_editor_style_updated_cb (wk_editor);
+       webkit_editor_style_updated (wk_editor, FALSE);
 }
 
 static void
@@ -2059,6 +2067,9 @@ webkit_editor_insert_content (EContentEditor *editor,
        } else {
                g_warning ("%s: Unsupported flags combination (0x%x)", G_STRFUNC, flags);
        }
+
+       if (flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL)
+               webkit_editor_style_updated (wk_editor, TRUE);
 }
 
 static void
@@ -4727,7 +4738,7 @@ webkit_editor_style_settings_changed_cb (GSettings *settings,
                else
                        g_hash_table_remove (wk_editor->priv->old_settings, key);
 
-               webkit_editor_style_updated_cb (wk_editor);
+               webkit_editor_style_updated (wk_editor, FALSE);
        } else if (new_value) {
                g_variant_unref (new_value);
        }
@@ -4793,7 +4804,7 @@ webkit_editor_load_changed_cb (EWebKitEditor *wk_editor,
                g_queue_clear (wk_editor->priv->post_reload_operations);
        }
 
-       webkit_editor_style_updated_cb (wk_editor);
+       webkit_editor_style_updated (wk_editor, FALSE);
 
        if (wk_editor->priv->initialized_callback) {
                EContentEditorInitializedCallback initialized_callback;


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