[evolution] EHTMLEditorActions - Optimize history saving for 'Cut' action



commit 63ccee5cba02ce4360328f770d235f4395c7488c
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Apr 30 08:47:49 2015 +0200

    EHTMLEditorActions - Optimize history saving for 'Cut' action
    
    Avoid leakage of history event object when the selection is collapsed (no
    text to cut). Also don't count the caret coordinates after cut as they will
    be the same as the start point before the action.

 e-util/e-html-editor-actions.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c
index d0f8900..0fececc 100644
--- a/e-util/e-html-editor-actions.c
+++ b/e-util/e-html-editor-actions.c
@@ -545,6 +545,13 @@ action_cut_cb (GtkAction *action,
                return;
        }
 
+       range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
+       if (webkit_dom_range_get_collapsed (range, NULL)) {
+               g_object_unref (range);
+               g_object_unref (dom_selection);
+               return;
+       }
+
        selection = e_html_editor_view_get_selection (view);
 
        ev = g_new0 (EHTMLEditorViewHistoryEvent, 1);
@@ -552,13 +559,6 @@ action_cut_cb (GtkAction *action,
 
        e_html_editor_selection_get_selection_coordinates (
                selection, &ev->before.start.x, &ev->before.start.y, &ev->before.end.x, &ev->before.end.y);
-       range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
-
-       if (webkit_dom_range_get_collapsed (range, NULL)) {
-               g_object_unref (range);
-               g_object_unref (dom_selection);
-               return;
-       }
 
        /* Save the fragment. */
        fragment = webkit_dom_range_clone_contents (range, NULL);
@@ -568,8 +568,10 @@ action_cut_cb (GtkAction *action,
 
        webkit_web_view_cut_clipboard (WEBKIT_WEB_VIEW (view));
 
-       e_html_editor_selection_get_selection_coordinates (
-               selection, &ev->after.start.x, &ev->after.start.y, &ev->after.end.x, &ev->after.end.y);
+       ev->after.start.x = ev->before.start.x;
+       ev->after.start.y = ev->before.start.y;
+       ev->after.end.x = ev->before.start.x;
+       ev->after.end.y = ev->before.start.y;
 
        e_html_editor_view_insert_new_history_event (view, ev);
 


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