[evolution/wip/webkit2] EHTMLEditorView - Short lines are concatenated into one



commit d3540756abacd365716d58a106cc736a207e9d8c
Author: Tomas Popela <tpopela redhat com>
Date:   Mon Mar 23 14:02:56 2015 +0100

    EHTMLEditorView - Short lines are concatenated into one

 web-extensions/e-html-editor-view-dom-functions.c |   27 +++++++++++++++-----
 1 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/web-extensions/e-html-editor-view-dom-functions.c 
b/web-extensions/e-html-editor-view-dom-functions.c
index c908a45..38fe59d 100644
--- a/web-extensions/e-html-editor-view-dom-functions.c
+++ b/web-extensions/e-html-editor-view-dom-functions.c
@@ -3087,7 +3087,8 @@ get_decoded_line_length (WebKitDOMDocument *document,
 
 static gboolean
 check_if_end_paragraph (const gchar *input,
-                        glong length)
+                        glong length,
+                        gboolean preserve_next_line)
 {
        const gchar *next_space;
 
@@ -3108,6 +3109,11 @@ check_if_end_paragraph (const gchar *input,
 
                if (length_next_word + length < 72)
                        return TRUE;
+       } else {
+               /* If the current text to insert doesn't contain space we
+                * have to look on the previous line if we were preserving
+                * the block or not */
+               return !preserve_next_line;
        }
 
        return FALSE;
@@ -3132,6 +3138,7 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
        GRegex *regex_nbsp = NULL, *regex_link = NULL, *regex_email = NULL;
        GString *start, *end;
        WebKitDOMElement *paragraph = NULL;
+       gboolean preserve_next_line = TRUE;
 
        webkit_dom_html_element_set_inner_html (
                WEBKIT_DOM_HTML_ELEMENT (blockquote), "", NULL);
@@ -3145,12 +3152,14 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
 
        while (next_br) {
                gboolean local_ignore_next_br = ignore_next_br;
-               gboolean prevent_block = TRUE;
+               gboolean local_preserve_next_line = preserve_next_line;
+               gboolean preserve_block = TRUE;
                const gchar *citation = NULL, *citation_end = NULL;
                const gchar *rest = NULL, *with_br = NULL;
                gchar *to_insert = NULL;
 
                ignore_next_br = FALSE;
+               preserve_next_line = TRUE;
 
                to_insert = g_utf8_substring (
                        prev_br, 0, g_utf8_pointer_to_offset (prev_br, next_br));
@@ -3198,7 +3207,7 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
                        empty = !*truncated && strlen (rest) > 0;
 
                        if (strchr (" +- *=\t", *rest))
-                               prevent_block = FALSE;
+                               preserve_block = FALSE;
 
                        rest_to_insert = g_regex_replace_eval (
                                regex_nbsp,
@@ -3238,7 +3247,7 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
                        if (g_strcmp0 (rest_to_insert, UNICODE_ZERO_WIDTH_SPACE) == 0) {
                                paragraph = create_and_append_new_paragraph (
                                        document, extension, blockquote, block, "<br>");
-                       } else if (prevent_block) {
+                       } else if (preserve_block) {
                                gchar *html;
                                gchar *new_content;
 
@@ -3269,7 +3278,7 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
                                paragraph = create_and_append_new_paragraph (
                                        document, extension, blockquote, block, rest_to_insert);
 
-                       if (rest_to_insert && *rest_to_insert && prevent_block && paragraph) {
+                       if (rest_to_insert && *rest_to_insert && preserve_block && paragraph) {
                                glong length = 0;
 
                                if (strstr (rest, "&"))
@@ -3280,11 +3289,15 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
                                /* End the block if there is line with less that 62 characters. */
                                /* The shorter line can also mean that there is a long word on next
                                 * line (and the line was wrapped). So look at it and decide what to do. */
-                               if (length < 62 && check_if_end_paragraph (next_br, length))
+                               if (length < 62 && check_if_end_paragraph (next_br, length, 
local_preserve_next_line)) {
                                        append_new_paragraph (blockquote, &paragraph);
+                                       preserve_next_line = FALSE;
+                               }
 
-                               if (length > 72)
+                               if (length > 72) {
                                        append_new_paragraph (blockquote, &paragraph);
+                                       preserve_next_line = FALSE;
+                               }
                        }
 
                        citation_was_first_element = FALSE;


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