[evolution] EHTMLEditorView - Deleting a content in a PRE element could wrap the content in SPAN element
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorView - Deleting a content in a PRE element could wrap the content in SPAN element
- Date: Fri, 15 Apr 2016 10:46:13 +0000 (UTC)
commit b962cc71917db4d754c7210f3a6ecbfea5f314d5
Author: Tomas Popela <tpopela redhat com>
Date: Fri Apr 15 12:38:37 2016 +0200
EHTMLEditorView - Deleting a content in a PRE element could wrap the content in SPAN element
When deleting a content from a PRE element WebKit could wrap the content after
the caret and the end of the element into the SPAN element when a special style
attribute is set on the BODY. This could lead to various breaks in the composer.
To avoid it we need to rename the style attribute when deleting a content in the
plain text mode.
e-util/e-html-editor-view.c | 82 +++++++++++++++++++++++++++----------------
1 files changed, 52 insertions(+), 30 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 72d2409..6ddd986 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -3477,6 +3477,37 @@ body_key_up_event_process_return_key (EHTMLEditorView *view)
}
static void
+set_monospace_font_family_on_body (WebKitDOMElement *body,
+ gboolean html_mode)
+{
+ /* If copying some content in view, WebKit adds various information about
+ * the content's style (such as color, font size, ..) to the resulting HTML
+ * to correctly apply the style when pasting the content later. The thing
+ * is that in plain text mode the only font allowed is the monospaced one,
+ * but we are forcing it through user style sheet in WebKitWebSettings and
+ * sadly WebKit doesn't count with it, so when the content is pasted,
+ * WebKit wraps it inside SPANs and sets the font-family style on them.
+ * The problem is that when we switch to the HTML mode, the pasted content
+ * will have the monospaced font set. To avoid it we need to set the
+ * font-family style to the body, so WebKit will know about it and will
+ * avoid the described behaviour. */
+ /* When we are deleting a content from the PRE elements we need to turn
+ * this off, otherwise we will end with the same unwanted behavior (the
+ * text between the caret and the end of the element will be wrapped
+ * inside a SPAN element. */
+ if (!html_mode) {
+ dom_element_rename_attribute (WEBKIT_DOM_ELEMENT (body), "data-style", "style");
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (body),
+ "style",
+ "font-family: Monospace;",
+ NULL);
+ } else {
+ dom_element_rename_attribute (WEBKIT_DOM_ELEMENT (body), "style", "data-style");
+ }
+}
+
+static void
body_keyup_event_cb (WebKitDOMElement *element,
WebKitDOMUIEvent *event,
EHTMLEditorView *view)
@@ -3493,6 +3524,15 @@ body_keyup_event_cb (WebKitDOMElement *element,
key_code = webkit_dom_ui_event_get_key_code (event);
if (key_code == HTML_KEY_CODE_BACKSPACE || key_code == HTML_KEY_CODE_DELETE) {
+ if (!view->priv->html_mode) {
+ WebKitDOMDocument *document;
+ WebKitDOMHTMLElement *body;
+
+ document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
+ body = webkit_dom_document_get_body (document);
+
+ set_monospace_font_family_on_body (WEBKIT_DOM_ELEMENT (body), FALSE);
+ }
body_key_up_event_process_backspace_or_delete (view, key_code == HTML_KEY_CODE_DELETE);
/* The content was wrapped and the coordinates
@@ -6080,9 +6120,18 @@ html_editor_view_key_press_event (GtkWidget *widget,
return TRUE;
}
- if ((event->keyval == GDK_KEY_Delete || event->keyval == GDK_KEY_BackSpace) &&
- key_press_event_process_delete_or_backspace_key (view, event->keyval == GDK_KEY_Delete, event)) {
- return TRUE;
+ if (event->keyval == GDK_KEY_Delete || event->keyval == GDK_KEY_BackSpace) {
+ if (key_press_event_process_delete_or_backspace_key (view, event->keyval == GDK_KEY_Delete,
event))
+ return TRUE;
+ else if (!view->priv->html_mode) {
+ WebKitDOMDocument *document;
+ WebKitDOMHTMLElement *body;
+
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
+ body = webkit_dom_document_get_body (document);
+
+ set_monospace_font_family_on_body (WEBKIT_DOM_ELEMENT (body), TRUE);
+ }
}
/* Chain up to parent's key_press_event() method. */
@@ -8109,33 +8158,6 @@ register_html_events_handlers (EHTMLEditorView *view,
}
static void
-set_monospace_font_family_on_body (WebKitDOMElement *body,
- gboolean html_mode)
-{
- /* If copying some content in view, WebKit adds various information about
- * the content's style (such as color, font size, ..) to the resulting HTML
- * to correctly apply the style when pasting the content later. The thing
- * is that in plain text mode the only font allowed is the monospaced one,
- * but we are forcing it through user style sheet in WebKitWebSettings and
- * sadly WebKit doesn't count with it, so when the content is pasted,
- * WebKit wraps it inside SPANs and sets the font-family style on them.
- * The problem is that when we switch to the HTML mode, the pasted content
- * will have the monospaced font set. To avoid it we need to set the
- * font-family style to the body, so WebKit will know about it and will
- * avoid the described behaviour. */
- if (!html_mode) {
- dom_element_rename_attribute (WEBKIT_DOM_ELEMENT (body), "data-style", "style");
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (body),
- "style",
- "font-family: Monospace;",
- NULL);
- } else {
- dom_element_rename_attribute (WEBKIT_DOM_ELEMENT (body), "style", "data-style");
- }
-}
-
-static void
html_editor_convert_view_content (EHTMLEditorView *view,
const gchar *preferred_text)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]