[evolution/wip/webkit-composer: 350/372] EEditorWidget: Remove unneeded Unicode ZERO WIDTH SPACE characters while typing
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer: 350/372] EEditorWidget: Remove unneeded Unicode ZERO WIDTH SPACE characters while typing
- Date: Thu, 6 Feb 2014 11:52:56 +0000 (UTC)
commit d598d824c23b92c3d18801e168715a87e71cf25f
Author: Tomas Popela <tpopela redhat com>
Date: Mon Jan 27 15:26:48 2014 +0100
EEditorWidget: Remove unneeded Unicode ZERO WIDTH SPACE characters while typing
Also rename UNICODE_HIDDEN_SPACE to UNICODE_ZERO_WIDTH_SPACE
composer/e-composer-private.c | 4 +-
e-util/e-editor-selection.c | 18 +++++++-------
e-util/e-editor-widget.c | 48 +++++++++++++++++++++++++++++++++++++++-
3 files changed, 57 insertions(+), 13 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index a0a7d3f..d58180d 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -27,7 +27,7 @@
/* Initial height of the picture gallery. */
#define GALLERY_INITIAL_HEIGHT 150
-#define UNICODE_HIDDEN_SPACE "\xe2\x80\x8b"
+#define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
static void
composer_setup_charset_menu (EMsgComposer *composer)
@@ -874,7 +874,7 @@ composer_move_caret (EMsgComposer *composer)
webkit_dom_element_set_id (
WEBKIT_DOM_ELEMENT (element), "-x-evo-input-start");
webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (element), UNICODE_HIDDEN_SPACE, NULL);
+ WEBKIT_DOM_HTML_ELEMENT (element), UNICODE_ZERO_WIDTH_SPACE, NULL);
}
if (start_bottom) {
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 8f62412..2f99cad 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -39,7 +39,7 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_EDITOR_SELECTION, EEditorSelectionPrivate))
-#define UNICODE_HIDDEN_SPACE "\xe2\x80\x8b"
+#define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
#define SPACES_PER_INDENTATION 4
/**
@@ -1439,7 +1439,7 @@ e_editor_selection_set_block_format (EEditorSelection *selection,
WebKitDOMNode *paragraph_node = webkit_dom_node_list_item (list, ii);
content = webkit_dom_node_get_text_content (paragraph_node);
- if (g_strcmp0 (content, UNICODE_HIDDEN_SPACE) == 0) {
+ if (g_strcmp0 (content, UNICODE_ZERO_WIDTH_SPACE) == 0) {
webkit_dom_node_set_text_content (paragraph_node, "", NULL);
}
g_free (content);
@@ -1450,7 +1450,7 @@ e_editor_selection_set_block_format (EEditorSelection *selection,
/* We have to use again the hidden space to move caret into newly
* inserted list */
- content = g_strconcat ("<li>", UNICODE_HIDDEN_SPACE, "</li>", NULL);
+ content = g_strconcat ("<li>", UNICODE_ZERO_WIDTH_SPACE, "</li>", NULL);
webkit_dom_html_element_set_inner_html (
WEBKIT_DOM_HTML_ELEMENT (element),
content,
@@ -2369,7 +2369,7 @@ e_editor_selection_set_monospaced (EEditorSelection *selection,
/* https://bugs.webkit.org/show_bug.cgi?id=15256 */
webkit_dom_html_element_set_inner_html (
WEBKIT_DOM_HTML_ELEMENT (tt_element),
- UNICODE_HIDDEN_SPACE, NULL);
+ UNICODE_ZERO_WIDTH_SPACE, NULL);
webkit_dom_range_insert_node (range, WEBKIT_DOM_NODE (tt_element), NULL);
move_caret_into_element (document, tt_element);
@@ -2447,7 +2447,7 @@ e_editor_selection_set_monospaced (EEditorSelection *selection,
webkit_dom_element_set_id (tt_element, "ev-tt");
inner_html = webkit_dom_html_element_get_inner_html (WEBKIT_DOM_HTML_ELEMENT
(tt_element));
- result = e_str_replace_string (inner_html, UNICODE_HIDDEN_SPACE, "");
+ result = e_str_replace_string (inner_html, UNICODE_ZERO_WIDTH_SPACE, "");
if (result) {
webkit_dom_html_element_set_inner_html (
WEBKIT_DOM_HTML_ELEMENT (tt_element),
@@ -2457,7 +2457,7 @@ e_editor_selection_set_monospaced (EEditorSelection *selection,
}
outer_html = webkit_dom_html_element_get_outer_html (WEBKIT_DOM_HTML_ELEMENT
(tt_element));
- tmp = g_strconcat (outer_html, UNICODE_HIDDEN_SPACE, NULL);
+ tmp = g_strconcat (outer_html, UNICODE_ZERO_WIDTH_SPACE, NULL);
webkit_dom_html_element_set_outer_html (
WEBKIT_DOM_HTML_ELEMENT (tt_element),
tmp, NULL);
@@ -3629,7 +3629,7 @@ wrap_lines (EEditorSelection *selection,
/* If there is temporary hidden space we remove it */
text_content = webkit_dom_node_get_text_content (node);
- if (g_strstr_len (text_content, -1, UNICODE_HIDDEN_SPACE)) {
+ if (g_strstr_len (text_content, -1, UNICODE_ZERO_WIDTH_SPACE)) {
webkit_dom_character_data_delete_data (
WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, NULL);
g_free (text_content);
@@ -4005,12 +4005,12 @@ e_editor_selection_wrap_lines (EEditorSelection *selection)
text_content = webkit_dom_node_get_text_content (paragraph);
/* If there is hidden space character in the beginning we remove it */
- if (g_strstr_len (text_content, -1, UNICODE_HIDDEN_SPACE)) {
+ if (g_strstr_len (text_content, -1, UNICODE_ZERO_WIDTH_SPACE)) {
WebKitDOMNode *child = webkit_dom_node_get_first_child (paragraph);
if (WEBKIT_DOM_IS_CHARACTER_DATA (child)) {
GString *result = e_str_replace_string (
- text_content, UNICODE_HIDDEN_SPACE, "");
+ text_content, UNICODE_ZERO_WIDTH_SPACE, "");
if (result) {
webkit_dom_character_data_set_data (
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index c55158f..fe0f2fd 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -35,7 +35,7 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_EDITOR_WIDGET, EEditorWidgetPrivate))
-#define UNICODE_HIDDEN_SPACE "\xe2\x80\x8b"
+#define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
#define URL_PATTERN \
"((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?" \
@@ -304,15 +304,59 @@ e_editor_widget_force_spellcheck (EEditorWidget *widget)
}
static void
+body_input_event_cb (WebKitDOMElement *element,
+ WebKitDOMEvent *event,
+ EEditorWidget *editor_widget)
+{
+ WebKitDOMNode *node;
+ WebKitDOMRange *range = editor_widget_get_dom_range (editor_widget);
+
+ /* If text before caret includes UNICODE_ZERO_WIDTH_SPACE character, remove it */
+ node = webkit_dom_range_get_end_container (range, NULL);
+ if (WEBKIT_DOM_IS_TEXT (node)) {
+ gchar *text = webkit_dom_node_get_text_content (node);
+ if (strstr (text, UNICODE_ZERO_WIDTH_SPACE)) {
+ WebKitDOMDocument *document;
+ WebKitDOMDOMWindow *window;
+ WebKitDOMDOMSelection *selection;
+
+ GString *res = e_str_replace_string (text, UNICODE_ZERO_WIDTH_SPACE, "");
+
+ webkit_dom_node_set_text_content (node, res->str, NULL);
+
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (editor_widget));
+ window = webkit_dom_document_get_default_view (document);
+ selection = webkit_dom_dom_window_get_selection (window);
+
+ webkit_dom_dom_selection_modify (selection, "move", "right", "character");
+
+ g_string_free (res, TRUE);
+ }
+ g_free (text);
+ }
+}
+
+
+static void
editor_widget_load_status_changed (EEditorWidget *widget)
{
WebKitLoadStatus status;
+ WebKitDOMDocument *document;
status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (widget));
if (status != WEBKIT_LOAD_FINISHED)
return;
widget->priv->reload_in_progress = FALSE;
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (widget));
+
+ /* Register on input event that is called when the content (body) is modified */
+ webkit_dom_event_target_add_event_listener (
+ WEBKIT_DOM_EVENT_TARGET (webkit_dom_document_get_body (document)),
+ "input",
+ G_CALLBACK (body_input_event_cb),
+ FALSE,
+ widget);
/* Dispatch queued operations */
while (widget->priv->postreload_operations &&
@@ -2327,7 +2371,7 @@ process_elements (WebKitDOMNode *node,
nodes = webkit_dom_node_get_child_nodes (node);
length = webkit_dom_node_list_get_length (nodes);
regex = g_regex_new ("\x9", 0, 0, NULL);
- regex_hidden_space = g_regex_new (UNICODE_HIDDEN_SPACE, 0, 0, NULL);
+ regex_hidden_space = g_regex_new (UNICODE_ZERO_WIDTH_SPACE, 0, 0, NULL);
for (ii = 0; ii < length; ii++) {
WebKitDOMNode *child;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]