summaryrefslogtreecommitdiff
path: root/legacy/evas
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2012-10-17 06:58:38 +0000
committerTom Hacohen <tom@stosb.com>2012-10-17 06:58:38 +0000
commit03e291eebbccf663621e5f95b72efd76a188ffb2 (patch)
tree33e3a6d96ce6ded81e059fedee0d5499ea74d16f /legacy/evas
parentb284a80e767fd8b14345f366518c958196344e3a (diff)
Evas textblock: Fixed issues when deleting some ranges.
An example broken range: "A<ps/><b>B</b>". Many thanks to WooHyun for reporting this and providing most of the fix. SVN revision: 78105
Diffstat (limited to 'legacy/evas')
-rw-r--r--legacy/evas/src/lib/canvas/evas_object_textblock.c35
-rw-r--r--legacy/evas/src/tests/evas_test_textblock.c11
2 files changed, 16 insertions, 30 deletions
diff --git a/legacy/evas/src/lib/canvas/evas_object_textblock.c b/legacy/evas/src/lib/canvas/evas_object_textblock.c
index 638692aa59..fd96cd6191 100644
--- a/legacy/evas/src/lib/canvas/evas_object_textblock.c
+++ b/legacy/evas/src/lib/canvas/evas_object_textblock.c
@@ -6801,7 +6801,6 @@ _evas_textblock_node_text_adjust_offsets_to_start(Evas_Object_Textblock *o,
6801 Evas_Object_Textblock_Node_Text *n, size_t start, int end) 6801 Evas_Object_Textblock_Node_Text *n, size_t start, int end)
6802{ 6802{
6803 Evas_Object_Textblock_Node_Format *last_node, *itr; 6803 Evas_Object_Textblock_Node_Format *last_node, *itr;
6804 Evas_Object_Textblock_Node_Text *new_node;
6805 int use_end = 1; 6804 int use_end = 1;
6806 int delta = 0; 6805 int delta = 0;
6807 int first = 1; 6806 int first = 1;
@@ -6822,21 +6821,6 @@ _evas_textblock_node_text_adjust_offsets_to_start(Evas_Object_Textblock *o,
6822 end--; 6821 end--;
6823 } 6822 }
6824 6823
6825 /* If we are not removing the text node, all should stay in this text
6826 * node, otherwise, everything should move to the previous node */
6827 if ((start == 0) && !use_end)
6828 {
6829 new_node = _NODE_TEXT(EINA_INLIST_GET(n)->prev);
6830 if (!new_node)
6831 {
6832 new_node = n;
6833 }
6834 }
6835 else
6836 {
6837 new_node = n;
6838 }
6839
6840 /* Find the first node after start */ 6824 /* Find the first node after start */
6841 while (itr && (itr->text_node == n)) 6825 while (itr && (itr->text_node == n))
6842 { 6826 {
@@ -6894,7 +6878,6 @@ _evas_textblock_node_text_adjust_offsets_to_start(Evas_Object_Textblock *o,
6894 } 6878 }
6895 6879
6896 } 6880 }
6897 last_node->text_node = new_node;
6898 } 6881 }
6899 6882
6900 return EINA_FALSE; 6883 return EINA_FALSE;
@@ -7833,17 +7816,7 @@ evas_textblock_cursor_range_delete(Evas_Textblock_Cursor *cur1, Evas_Textblock_C
7833 { 7816 {
7834 should_merge = EINA_TRUE; 7817 should_merge = EINA_TRUE;
7835 } 7818 }
7836 else 7819 _evas_textblock_node_text_adjust_offsets_to_start(o, n1, cur1->pos, -1);
7837 {
7838 n = _NODE_TEXT(EINA_INLIST_GET(n1)->prev);
7839 /* Short path */
7840 if (!n)
7841 {
7842 /* Clear the whole textblock - do it nicer. */
7843 evas_object_textblock_text_markup_set(cur1->obj, "");
7844 return;
7845 }
7846 }
7847 } 7820 }
7848 else 7821 else
7849 { 7822 {
@@ -7857,7 +7830,6 @@ evas_textblock_cursor_range_delete(Evas_Textblock_Cursor *cur1, Evas_Textblock_C
7857 { 7830 {
7858 Evas_Object_Textblock_Node_Text *n; 7831 Evas_Object_Textblock_Node_Text *n;
7859 int len; 7832 int len;
7860 _evas_textblock_node_text_adjust_offsets_to_start(o, n1, cur1->pos, -1);
7861 n = _NODE_TEXT(EINA_INLIST_GET(n1)->next); 7833 n = _NODE_TEXT(EINA_INLIST_GET(n1)->next);
7862 /* Remove all the text nodes between */ 7834 /* Remove all the text nodes between */
7863 while (n && (n != n2)) 7835 while (n && (n != n2))
@@ -7865,10 +7837,13 @@ evas_textblock_cursor_range_delete(Evas_Textblock_Cursor *cur1, Evas_Textblock_C
7865 Evas_Object_Textblock_Node_Text *nnode; 7837 Evas_Object_Textblock_Node_Text *nnode;
7866 7838
7867 nnode = _NODE_TEXT(EINA_INLIST_GET(n)->next); 7839 nnode = _NODE_TEXT(EINA_INLIST_GET(n)->next);
7868 _evas_textblock_node_text_adjust_offsets_to_start(o, n, 0, -1);
7869 _evas_textblock_nodes_merge(o, n1); 7840 _evas_textblock_nodes_merge(o, n1);
7870 n = nnode; 7841 n = nnode;
7871 } 7842 }
7843 /* After we merged all the nodes, move the formats to the start of
7844 * the range. */
7845 _evas_textblock_node_text_adjust_offsets_to_start(o, n1, cur1->pos, -1);
7846
7872 should_merge = _evas_textblock_node_text_adjust_offsets_to_start(o, n2, 7847 should_merge = _evas_textblock_node_text_adjust_offsets_to_start(o, n2,
7873 0, cur2->pos); 7848 0, cur2->pos);
7874 7849
diff --git a/legacy/evas/src/tests/evas_test_textblock.c b/legacy/evas/src/tests/evas_test_textblock.c
index e8498f979a..e3fdfa8b6c 100644
--- a/legacy/evas/src/tests/evas_test_textblock.c
+++ b/legacy/evas/src/tests/evas_test_textblock.c
@@ -807,6 +807,17 @@ START_TEST(evas_textblock_format_removal)
807 fnode = evas_textblock_node_format_first_get(tb); 807 fnode = evas_textblock_node_format_first_get(tb);
808 fail_if(fnode); 808 fail_if(fnode);
809 809
810
811 /* Deleting a range with just one char and surrounded by formats, that
812 * deletes a paragraph. */
813 evas_object_textblock_text_markup_set(tb, "A<ps/><b>B</b>");
814 evas_textblock_cursor_pos_set(cur, 2);
815 evas_textblock_cursor_pos_set(main_cur, 3);
816 evas_textblock_cursor_range_delete(cur, main_cur);
817 fnode = evas_textblock_node_format_first_get(tb);
818 fnode = evas_textblock_node_format_next_get(fnode);
819 fail_if (fnode);
820
810 /* Two formats in the same place. */ 821 /* Two formats in the same place. */
811 evas_object_textblock_text_markup_set(tb, "a<b><a>b</a></b>b"); 822 evas_object_textblock_text_markup_set(tb, "a<b><a>b</a></b>b");
812 evas_textblock_cursor_pos_set(cur, 1); 823 evas_textblock_cursor_pos_set(cur, 1);