aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Popela <tpopela@redhat.com>2014-07-21 22:51:46 +0800
committerTomas Popela <tpopela@redhat.com>2014-07-21 23:02:08 +0800
commitbcbd85f9879e60ef291913f74a4d7ecdd70f9e17 (patch)
tree9ff6c4c28c1734c6d05232c85133636261d9efb5
parent5c08e2981273b719503cc2adc740b8e8ed235467 (diff)
downloadgsoc2013-evolution-bcbd85f9879e60ef291913f74a4d7ecdd70f9e17.tar.gz
gsoc2013-evolution-bcbd85f9879e60ef291913f74a4d7ecdd70f9e17.tar.zst
gsoc2013-evolution-bcbd85f9879e60ef291913f74a4d7ecdd70f9e17.zip
EHTMLEditorView - Wrap and quote just the first block after newly inserted line into the citation
Previously, the whole blockquote that was created after the newly inserted line was wrapped and quoted. Now just the first block is processed. Also rewrap the content as when enter was pressed in the middle of the paragraph the line ends wouldn't match the character count for word wrap.
-rw-r--r--e-util/e-html-editor-view.c132
1 files changed, 74 insertions, 58 deletions
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 493fa74a60..945b60a3e6 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -449,6 +449,62 @@ get_citation_level (WebKitDOMNode *node,
return level;
}
+static gchar *
+get_quotation_for_level (gint quote_level)
+{
+ gint ii;
+ GString *output = g_string_new ("");
+
+ for (ii = 0; ii < quote_level; ii++) {
+ g_string_append (output, "<span class=\"-x-evo-quote-character\">");
+ g_string_append (output, QUOTE_SYMBOL);
+ g_string_append (output, " ");
+ g_string_append (output, "</span>");
+ }
+
+ return g_string_free (output, FALSE);
+}
+
+static void
+quote_plain_text_element_after_wrapping (WebKitDOMDocument *document,
+ WebKitDOMElement *element,
+ gint quote_level)
+{
+ WebKitDOMNodeList *list;
+ WebKitDOMNode *quoted_node;
+ gint length, ii;
+ gchar *quotation;
+
+ quoted_node = WEBKIT_DOM_NODE (
+ webkit_dom_document_create_element (document, "SPAN", NULL));
+ webkit_dom_element_set_class_name (
+ WEBKIT_DOM_ELEMENT (quoted_node), "-x-evo-quoted");
+ quotation = get_quotation_for_level (quote_level);
+ webkit_dom_html_element_set_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (quoted_node), quotation, NULL);
+
+ list = webkit_dom_element_query_selector_all (
+ element, "br.-x-evo-wrap-br", NULL);
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (element),
+ quoted_node,
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
+ NULL);
+
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *br = webkit_dom_node_list_item (list, ii);
+
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (br),
+ webkit_dom_node_clone_node (quoted_node, TRUE),
+ webkit_dom_node_get_next_sibling (br),
+ NULL);
+ }
+
+ g_free (quotation);
+}
+
static WebKitDOMElement *
insert_new_line_into_citation (EHTMLEditorView *view,
const gchar *html_to_insert)
@@ -484,8 +540,24 @@ insert_new_line_into_citation (EHTMLEditorView *view,
WEBKIT_DOM_NODE (element));
if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (next_sibling)) {
- e_html_editor_view_quote_plain_text_element (
- view, WEBKIT_DOM_ELEMENT (next_sibling));
+ gint citation_level, length;
+ gint word_wrap_length =
+ e_html_editor_selection_get_word_wrap_length (selection);
+ WebKitDOMNode *node;
+
+ citation_level = get_citation_level (next_sibling, FALSE);
+ length = word_wrap_length - 2 * citation_level;
+
+ node = webkit_dom_node_get_first_child (next_sibling);
+ /* Rewrap and requote first block after the newly inserted line */
+ if (node && WEBKIT_DOM_IS_ELEMENT (node)) {
+ remove_quoting_from_element (WEBKIT_DOM_ELEMENT (node));
+ remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (node));
+ node = WEBKIT_DOM_NODE (e_html_editor_selection_wrap_paragraph_length (
+ selection, WEBKIT_DOM_ELEMENT (node), length));
+ quote_plain_text_element_after_wrapping (
+ document, WEBKIT_DOM_ELEMENT (node), citation_level);
+ }
e_html_editor_view_force_spell_check (view);
}
@@ -522,62 +594,6 @@ insert_new_line_into_citation (EHTMLEditorView *view,
return paragraph;
}
-static gchar *
-get_quotation_for_level (gint quote_level)
-{
- gint ii;
- GString *output = g_string_new ("");
-
- for (ii = 0; ii < quote_level; ii++) {
- g_string_append (output, "<span class=\"-x-evo-quote-character\">");
- g_string_append (output, QUOTE_SYMBOL);
- g_string_append (output, " ");
- g_string_append (output, "</span>");
- }
-
- return g_string_free (output, FALSE);
-}
-
-static void
-quote_plain_text_element_after_wrapping (WebKitDOMDocument *document,
- WebKitDOMElement *element,
- gint quote_level)
-{
- WebKitDOMNodeList *list;
- WebKitDOMNode *quoted_node;
- gint length, ii;
- gchar *quotation;
-
- quoted_node = WEBKIT_DOM_NODE (
- webkit_dom_document_create_element (document, "SPAN", NULL));
- webkit_dom_element_set_class_name (
- WEBKIT_DOM_ELEMENT (quoted_node), "-x-evo-quoted");
- quotation = get_quotation_for_level (quote_level);
- webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (quoted_node), quotation, NULL);
-
- list = webkit_dom_element_query_selector_all (
- element, "br.-x-evo-wrap-br", NULL);
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (element),
- quoted_node,
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
- NULL);
-
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++) {
- WebKitDOMNode *br = webkit_dom_node_list_item (list, ii);
-
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (br),
- webkit_dom_node_clone_node (quoted_node, TRUE),
- webkit_dom_node_get_next_sibling (br),
- NULL);
- }
-
- g_free (quotation);
-}
-
static void
body_input_event_cb (WebKitDOMElement *element,
WebKitDOMEvent *event,