[evolution] EHTMLEditorView - Simplify how an element is quoted
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorView - Simplify how an element is quoted
- Date: Wed, 1 Jun 2016 13:10:06 +0000 (UTC)
commit 38a6231731a511520091231180964b44a976bfbd
Author: Tomas Popela <tpopela redhat com>
Date: Wed Jun 1 15:04:29 2016 +0200
EHTMLEditorView - Simplify how an element is quoted
Just put the quotation marks on the beginning of the element.
e-util/e-html-editor-view.c | 84 ++++++++----------------------------------
1 files changed, 16 insertions(+), 68 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index f2b4118..cf3d492 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -6576,66 +6576,30 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
}
static void
-insert_quote_symbols (WebKitDOMHTMLElement *element,
- gint quote_level,
- gboolean skip_first,
- gboolean insert_newline)
+insert_quote_symbols (WebKitDOMDocument *document,
+ WebKitDOMHTMLElement *element,
+ gint quote_level)
{
- gchar *text;
- gint ii;
- GString *output;
gchar *quotation;
+ WebKitDOMElement *quote_element;
if (!WEBKIT_DOM_IS_HTML_ELEMENT (element))
return;
- text = webkit_dom_html_element_get_inner_html (element);
- output = g_string_new ("");
quotation = get_quotation_for_level (quote_level);
- if (g_strcmp0 (text, "\n") == 0) {
- g_string_append (output, "<span class=\"-x-evo-quoted\">");
- g_string_append (output, quotation);
- g_string_append (output, "</span>");
- g_string_append (output, "\n");
- } else {
- gchar **lines;
-
- lines = g_strsplit (text, "\n", 0);
-
- for (ii = 0; lines[ii]; ii++) {
- if (ii == 0 && skip_first) {
- if (g_strv_length (lines) == 1) {
- g_strfreev (lines);
- goto exit;
- }
- g_string_append (output, lines[ii]);
- g_string_append (output, "\n");
- }
-
- g_string_append (output, "<span class=\"-x-evo-quoted\">");
- g_string_append (output, quotation);
- g_string_append (output, "</span>");
-
- /* Insert line of text */
- g_string_append (output, lines[ii]);
- if ((ii == g_strv_length (lines) - 1) &&
- !g_str_has_suffix (text, "\n") && !insert_newline) {
- /* If we are on last line and node's text doesn't
- * end with \n, don't insert it */
- break;
- }
- g_string_append (output, "\n");
- }
+ quote_element = webkit_dom_document_create_element (document, "span", NULL);
+ element_add_class (quote_element, "-x-evo-quote");
- g_strfreev (lines);
- }
+ webkit_dom_html_element_set_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (quote_element), quotation, NULL);
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (element),
+ WEBKIT_DOM_NODE (quote_element),
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
+ NULL);
- webkit_dom_html_element_set_inner_html (element, output->str, NULL);
- exit:
g_free (quotation);
- g_free (text);
- g_string_free (output, TRUE);
}
static void
@@ -6643,10 +6607,7 @@ quote_node (WebKitDOMDocument *document,
WebKitDOMNode *node,
gint quote_level)
{
- gboolean skip_first = FALSE;
- gboolean insert_newline = FALSE;
- gboolean is_html_node = FALSE;
- WebKitDOMNode *prev_sibling, *next_sibling;
+ WebKitDOMNode *next_sibling;
WebKitDOMNode *parent;
/* Don't quote when we are not in citation */
@@ -6658,25 +6619,12 @@ quote_node (WebKitDOMDocument *document,
if (WEBKIT_DOM_IS_HTML_ELEMENT (node)) {
insert_quote_symbols (
- WEBKIT_DOM_HTML_ELEMENT (node), quote_level, FALSE, FALSE);
+ document, WEBKIT_DOM_HTML_ELEMENT (node), quote_level);
return;
}
- prev_sibling = webkit_dom_node_get_previous_sibling (node);
next_sibling = webkit_dom_node_get_next_sibling (node);
- is_html_node =
- !WEBKIT_DOM_IS_TEXT (prev_sibling) &&
- !WEBKIT_DOM_IS_COMMENT (prev_sibling) && (
- WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (prev_sibling) ||
- element_has_tag (WEBKIT_DOM_ELEMENT (prev_sibling), "b") ||
- element_has_tag (WEBKIT_DOM_ELEMENT (prev_sibling), "i") ||
- element_has_tag (WEBKIT_DOM_ELEMENT (prev_sibling), "u") ||
- element_has_class (WEBKIT_DOM_ELEMENT (prev_sibling), "Apple-tab-span"));
-
- if (prev_sibling && is_html_node)
- skip_first = TRUE;
-
/* Skip the BR between first blockquote and pre */
if (quote_level == 1 && next_sibling && WEBKIT_DOM_IS_HTML_PRE_ELEMENT (next_sibling))
return;
@@ -6684,7 +6632,7 @@ quote_node (WebKitDOMDocument *document,
parent = webkit_dom_node_get_parent_node (node),
insert_quote_symbols (
- WEBKIT_DOM_HTML_ELEMENT (parent), quote_level, skip_first, insert_newline);
+ document, WEBKIT_DOM_HTML_ELEMENT (parent), quote_level);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]