[evolution/wip/webkit2] EHTMLEditorView - Undo behaves wrongly when undoing smiley
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] EHTMLEditorView - Undo behaves wrongly when undoing smiley
- Date: Wed, 22 Apr 2015 13:17:17 +0000 (UTC)
commit 368a439b66a27920e286a48756ec42fd99549b29
Author: Tomas Popela <tpopela redhat com>
Date: Wed Apr 22 12:57:05 2015 +0200
EHTMLEditorView - Undo behaves wrongly when undoing smiley
The things is that we need to manually insert the input event into
history when we wrote i.e. ":)" smiley that was recognize and inserted as
":-)". Without this newly inserted event the bracket was never removed
while doing undo.
web-extensions/e-html-editor-undo-redo-manager.c | 75 +++++++++++++++++++++
web-extensions/e-html-editor-undo-redo-manager.h | 4 +
web-extensions/e-html-editor-view-dom-functions.c | 10 ++-
3 files changed, 87 insertions(+), 2 deletions(-)
---
diff --git a/web-extensions/e-html-editor-undo-redo-manager.c
b/web-extensions/e-html-editor-undo-redo-manager.c
index 6087a84..e373376 100644
--- a/web-extensions/e-html-editor-undo-redo-manager.c
+++ b/web-extensions/e-html-editor-undo-redo-manager.c
@@ -1461,6 +1461,81 @@ e_html_editor_undo_redo_manager_get_current_history_event (EHTMLEditorUndoRedoMa
return NULL;
}
+void
+e_html_editor_undo_redo_manager_insert_dash_history_event (EHTMLEditorUndoRedoManager *manager)
+{
+ EHTMLEditorHistoryEvent *event, *last;
+ GList *history;
+ WebKitDOMDocumentFragment *fragment;
+ WebKitDOMDocument *document;
+
+ g_return_if_fail (E_IS_HTML_EDITOR_UNDO_REDO_MANAGER (manager));
+
+ event = g_new0 (EHTMLEditorHistoryEvent, 1);
+ event->type = HISTORY_INPUT;
+
+ document = manager->priv->document;
+ fragment = webkit_dom_document_create_document_fragment (document);
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (fragment),
+ WEBKIT_DOM_NODE (
+ webkit_dom_document_create_text_node (document, "-")),
+ NULL);
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (fragment),
+ WEBKIT_DOM_NODE (
+ dom_create_selection_marker (document, TRUE)),
+ NULL);
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (fragment),
+ WEBKIT_DOM_NODE (
+ dom_create_selection_marker (document, FALSE)),
+ NULL);
+ event->data.fragment = fragment;
+
+ last = e_html_editor_undo_redo_manager_get_current_history_event (manager);
+ /* The dash event needs to have the same coordinates as the character
+ * that is right after it. */
+ event->after.start.x = last->after.start.x;
+ event->after.start.y = last->after.start.y;
+ event->after.end.x = last->after.end.x;
+ event->after.end.y = last->after.end.y;
+
+ history = manager->priv->history;
+ while (history) {
+ EHTMLEditorHistoryEvent *item;
+ WebKitDOMNode *first_child;
+
+ item = history->data;
+
+ if (item->type != HISTORY_INPUT)
+ break;
+
+ first_child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (item->data.fragment));
+ if (WEBKIT_DOM_IS_TEXT (first_child)) {
+ gchar *text;
+
+ text = webkit_dom_node_get_text_content (first_child);
+ if (text && *text == ':') {
+ guint diff;
+
+ diff = event->after.start.x - item->after.start.x;
+
+ /* We need to move the coordinater of the last
+ * event by one character. */
+ last->after.start.x += diff;
+ last->after.end.x += diff;
+
+ manager->priv->history = g_list_insert_before (
+ manager->priv->history, history, event);
+ }
+ g_free (text);
+ break;
+ }
+ history = history->next;
+ }
+}
+
gboolean
e_html_editor_undo_redo_manager_can_undo (EHTMLEditorUndoRedoManager *manager)
{
diff --git a/web-extensions/e-html-editor-undo-redo-manager.h
b/web-extensions/e-html-editor-undo-redo-manager.h
index a1d227e..a60dcca 100644
--- a/web-extensions/e-html-editor-undo-redo-manager.h
+++ b/web-extensions/e-html-editor-undo-redo-manager.h
@@ -82,6 +82,10 @@ EHTMLEditorHistoryEvent *
e_html_editor_undo_redo_manager_get_current_history_event
(EHTMLEditorUndoRedoManager *manager);
+void
+e_html_editor_undo_redo_manager_insert_dash_history_event
+ (EHTMLEditorUndoRedoManager *manager);
+
gboolean e_html_editor_undo_redo_manager_can_undo
(EHTMLEditorUndoRedoManager *manager);
diff --git a/web-extensions/e-html-editor-view-dom-functions.c
b/web-extensions/e-html-editor-view-dom-functions.c
index 0b78b91..80ddf98 100644
--- a/web-extensions/e-html-editor-view-dom-functions.c
+++ b/web-extensions/e-html-editor-view-dom-functions.c
@@ -1287,8 +1287,8 @@ emoticon_insert_span (EEmoticon *emoticon,
g_utf8_strlen (node_text, -1) - strlen (emoticon_start),
strlen (emoticon->text_face),
NULL);
- } else {
- gboolean same = TRUE;
+ } else if (strstr (emoticon->text_face, "-")) {
+ gboolean same = TRUE, compensate = FALSE;
gint ii = 0, jj = 0;
/* Try to recognize smileys without the dash e.g. :). */
@@ -1297,6 +1297,7 @@ emoticon_insert_span (EEmoticon *emoticon,
if (emoticon->text_face[jj+1] && emoticon->text_face[jj+1] ==
'-')
ii++;
jj+=2;
+ compensate = TRUE;
continue;
}
if (emoticon_start[ii] == emoticon->text_face[jj]) {
@@ -1312,6 +1313,11 @@ emoticon_insert_span (EEmoticon *emoticon,
ii,
NULL);
}
+ /* If we recognize smiley without dash, but we inserted
+ * the text version with dash we need it insert new
+ * history input event with that dash. */
+ if (compensate)
+ e_html_editor_undo_redo_manager_insert_dash_history_event (manager);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]