I#1950 - Composer: Copy/paste changes text size in HTML mode

Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1950
This commit is contained in:
Milan Crha
2023-03-31 07:42:47 +02:00
parent b006276369
commit dcb06707f2
2 changed files with 29 additions and 3 deletions

View File

@ -5393,10 +5393,17 @@ EvoEditor.InsertContent = function(text, isHTML, quote, preferPre)
}
if (isHTML) {
var isPaste = false;
content.innerHTML = text;
// paste can contain <meta> elements, like the one with Content-Type, which can be removed
while (content.firstElementChild && content.firstElementChild.tagName == "META") {
if (!isPaste &&
content.firstElementChild.hasAttribute("name") &&
content.firstElementChild.getAttribute("name") == "x-evolution-is-paste")
isPaste = true;
content.removeChild(content.firstElementChild);
}
@ -5411,12 +5418,24 @@ EvoEditor.InsertContent = function(text, isHTML, quote, preferPre)
while (node) {
var removeNode = false;
// workaround https://bugs.webkit.org/show_bug.cgi?id=250003
if (isPaste && node.nodeType == node.ELEMENT_NODE && node.tagName != "SPAN" &&
node.hasAttribute("style")) {
node.removeAttribute("style");
}
if (node.nodeType == node.ELEMENT_NODE && node.tagName == "P") {
removeNode = true;
var div = document.createElement("DIV");
EvoEditor.moveNodeContent(node, div);
node.parentElement.insertBefore(div, node.nextSibling);
// workaround https://bugs.webkit.org/show_bug.cgi?id=250003
} else if (isPaste && node.nodeType == node.ELEMENT_NODE && node.tagName == "SPAN" &&
node.attributes.length == 1 && node.attributes[0].name == "style" &&
node.style.length > 0 && node.fontSize != "") {
EvoEditor.moveNodeContent(node, null);
removeNode = true;
}
next = EvoEditor.getNextNodeInHierarchy(node, content);

View File

@ -5123,18 +5123,25 @@ webkit_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
return;
}
if (is_html)
if (is_html) {
gchar *paste_content;
paste_content = g_strconcat ("<meta name=\"x-evolution-is-paste\">", content, NULL);
webkit_editor_insert_content (
E_CONTENT_EDITOR (wk_editor),
content,
paste_content,
E_CONTENT_EDITOR_INSERT_TEXT_HTML);
else
g_free (paste_content);
} else {
webkit_editor_insert_content (
E_CONTENT_EDITOR (wk_editor),
content,
E_CONTENT_EDITOR_INSERT_TEXT_PLAIN |
E_CONTENT_EDITOR_INSERT_CONVERT |
(wk_editor->priv->paste_plain_prefer_pre ? E_CONTENT_EDITOR_INSERT_CONVERT_PREFER_PRE : 0));
}
g_free (content);
}