[evolution/wip/webkit-composer] The unicode hidden space character can also be on the end of word and not only at the beginning
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer] The unicode hidden space character can also be on the end of word and not only at the beginning
- Date: Wed, 19 Mar 2014 12:22:29 +0000 (UTC)
commit 24025a323c97142481847b7307e5c0088fc2e1bd
Author: Tomas Popela <tpopela redhat com>
Date: Wed Mar 19 13:21:10 2014 +0100
The unicode hidden space character can also be on the end of word and not only at the beginning
e-util/e-editor-selection.c | 48 +++++++++++++++++++++++++++++-------------
e-util/e-editor-widget.c | 13 ++++++++---
2 files changed, 42 insertions(+), 19 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 9d1fe46..43db182 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -4255,9 +4255,19 @@ 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_ZERO_WIDTH_SPACE)) {
- webkit_dom_character_data_delete_data (
- WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, NULL);
+ if (strstr (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+ if (g_str_has_prefix (text_content, UNICODE_ZERO_WIDTH_SPACE))
+ webkit_dom_character_data_delete_data (
+ WEBKIT_DOM_CHARACTER_DATA (node),
+ 0,
+ 1,
+ NULL);
+ if (g_str_has_suffix (text_content, UNICODE_ZERO_WIDTH_SPACE))
+ webkit_dom_character_data_delete_data (
+ WEBKIT_DOM_CHARACTER_DATA (node),
+ g_utf8_strlen (text_content, -1) -1,
+ 1,
+ NULL);
g_free (text_content);
text_content = webkit_dom_node_get_text_content (node);
}
@@ -4669,20 +4679,28 @@ 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_ZERO_WIDTH_SPACE)) {
- WebKitDOMNode *child = webkit_dom_node_get_first_child (paragraph);
+ if (strstr (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+ if (g_str_has_prefix (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+ WebKitDOMNode *node;
- if (WEBKIT_DOM_IS_CHARACTER_DATA (child)) {
- GString *result = e_str_replace_string (
- text_content, UNICODE_ZERO_WIDTH_SPACE, "");
+ node = webkit_dom_node_get_first_child (paragraph);
- if (result) {
- webkit_dom_character_data_set_data (
- WEBKIT_DOM_CHARACTER_DATA (child),
- result->str,
- NULL);
- g_string_free (result, TRUE);
- }
+ webkit_dom_character_data_delete_data (
+ WEBKIT_DOM_CHARACTER_DATA (node),
+ 0,
+ 1,
+ NULL);
+ }
+ if (g_str_has_suffix (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+ WebKitDOMNode *node;
+
+ node = webkit_dom_node_get_last_child (paragraph);
+
+ webkit_dom_character_data_delete_data (
+ WEBKIT_DOM_CHARACTER_DATA (node),
+ g_utf8_strlen (text_content, -1) -1,
+ 1,
+ NULL);
}
}
g_free (text_content);
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index c9ff3a5..44e92b8 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -449,9 +449,13 @@ body_input_event_cb (WebKitDOMElement *element,
/* We have to preserve empty paragraphs with just UNICODE_ZERO_WIDTH_SPACE
* character as when we will remove it it will collapse */
- if (length > 1 && g_str_has_prefix (text, UNICODE_ZERO_WIDTH_SPACE)) {
- webkit_dom_character_data_replace_data (
- WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, "", NULL);
+ if (length > 1) {
+ if (g_str_has_prefix (text, UNICODE_ZERO_WIDTH_SPACE))
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, "", NULL);
+ else if (g_str_has_suffix (text, UNICODE_ZERO_WIDTH_SPACE))
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (node), length - 1, 1, "", NULL);
}
g_free (text);
@@ -4157,8 +4161,9 @@ process_elements (EEditorWidget *widget,
regex = g_regex_new (UNICODE_ZERO_WIDTH_SPACE, 0, 0, NULL);
tmp = g_regex_replace (
regex, content, -1, 0, "", 0, NULL);
- g_free (content);
+ webkit_dom_node_set_text_content (child, tmp, NULL);
g_free (tmp);
+ g_free (content);
content = webkit_dom_node_get_text_content (child);
g_regex_unref (regex);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]