[evolution] EHTMLEditorSelection - Alignment could be wrong



commit 605f1ec43376f04596e3475c337d09bbc63bb908
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Jun 26 07:55:39 2015 +0200

    EHTMLEditorSelection - Alignment could be wrong
    
    When determining alignment we have to look at element's classes not
    just in case it is a list item, but in general as other elements
    can have these classes set. Also when changing the block format save
    the alignment before the change as after the change the value
    in selection->priv->alignment will be reseted thus we wouldn't preserve
    the alignment across format change.

 e-util/e-html-editor-selection.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 24ee032..fe58f55 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -1217,28 +1217,29 @@ e_html_editor_selection_get_alignment (EHTMLEditorSelection *selection)
                E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT);
 
        range = html_editor_selection_get_current_range (selection);
-       if (!range)
-               return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+       if (!range) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+               goto out;
+       }
 
        node = webkit_dom_range_get_start_container (range, NULL);
        g_object_unref (range);
-       if (!node)
-               return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+       if (!node) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+               goto out;
+       }
 
        if (WEBKIT_DOM_IS_ELEMENT (node))
                element = WEBKIT_DOM_ELEMENT (node);
        else
                element = webkit_dom_node_get_parent_element (node);
 
-       if (WEBKIT_DOM_IS_HTMLLI_ELEMENT (element)) {
-               if (element_has_class (element, "-x-evo-align-right"))
-                       alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT;
-               else if (element_has_class (element, "-x-evo-align-center"))
-                       alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER;
-               else
-                       alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
-
-               return alignment;
+       if (element_has_class (element, "-x-evo-align-right")) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT;
+               goto out;
+       } else if (element_has_class (element, "-x-evo-align-center")) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER;
+               goto out;
        }
 
        style = webkit_dom_element_get_style (element);
@@ -1258,6 +1259,9 @@ e_html_editor_selection_get_alignment (EHTMLEditorSelection *selection)
        g_object_unref (style);
        g_free (value);
 
+ out:
+       selection->priv->alignment = alignment;
+
        return alignment;
 }
 
@@ -2672,6 +2676,7 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
 {
        EHTMLEditorView *view;
        EHTMLEditorSelectionBlockFormat current_format;
+       EHTMLEditorSelectionAlignment current_alignment;
        EHTMLEditorViewHistoryEvent *ev = NULL;
        const gchar *value;
        gboolean from_list = FALSE, to_list = FALSE, html_mode;
@@ -2752,6 +2757,8 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
                return;
        }
 
+       current_alignment = selection->priv->alignment;
+
        e_html_editor_selection_save (selection);
 
        if (!e_html_editor_view_is_undo_redo_in_progress (view)) {
@@ -2834,7 +2841,7 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
        e_html_editor_view_force_spell_check_for_current_paragraph (view);
 
        /* When changing the format we need to re-set the alignment */
-       e_html_editor_selection_set_alignment (selection, selection->priv->alignment);
+       e_html_editor_selection_set_alignment (selection, current_alignment);
 
        e_html_editor_view_set_changed (view, TRUE);
 


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