hermet pushed a commit to branch master. http://git.enlightenment.org/tools/enventor.git/commit/?id=1fd611f4b617cc04b9f574ba94759d808af00ee0
commit 1fd611f4b617cc04b9f574ba94759d808af00ee0 Author: Mykyta Biliavskyi <m.biliavs...@samsung.com> Date: Fri Sep 4 15:42:43 2015 +0900 Edc_editor: enhance enventor_object_text insert API. Summary: added edit_text_insert function, that shared for public use as enventor_object_text_insert This API provide functionality for text insert with support correct text replacement and redo/undo feature support. @fix T2691 Test Plan: Lunch Enventor. Open "Find/Replace" dialog. Fill "Find" field with exist string and fill "Replace with" field with any text. Press "Replace All". Close dialog window and check how work Ctrl+Z and Ctrl+R hotkey combinations. Reviewers: Hermet Maniphest Tasks: T2691 Differential Revision: https://phab.enlightenment.org/D3005 --- src/lib/edc_editor.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/lib/enventor_private.h | 1 + src/lib/enventor_smart.c | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c index 4b7e6d4..e765a7c 100644 --- a/src/lib/edc_editor.c +++ b/src/lib/edc_editor.c @@ -670,6 +670,47 @@ edit_selection_start_cb(void *data, Evas_Object *obj EINA_UNUSED, ed->select_pos = elm_entry_cursor_pos_get(ed->en_edit); } +void +edit_text_insert(edit_data *ed, const char *text) +{ + const char *selection = elm_entry_selection_get(ed->en_edit); + selection = elm_entry_markup_to_utf8(selection); + if (!selection) + { + elm_entry_entry_set(ed->en_edit, text); + return; + } + int lenght = strlen(selection); + int pos_from = elm_entry_cursor_pos_get(ed->en_edit) - lenght; + + Evas_Object *tb = elm_entry_textblock_get(ed->en_edit); + Evas_Textblock_Cursor *cur = evas_object_textblock_cursor_get(tb); + int old_pos = evas_textblock_cursor_pos_get(cur); + evas_textblock_cursor_pos_set(cur, pos_from + lenght); + + /* append replacement text, and add relative diff into redoundo module */ + evas_textblock_cursor_pos_set(cur, pos_from + lenght); + evas_textblock_cursor_text_append(cur, text); + redoundo_text_relative_push(ed->rd, text); + + Evas_Textblock_Cursor *c_1 = evas_object_textblock_cursor_new(tb); + evas_textblock_cursor_pos_set(c_1, pos_from); + + Evas_Textblock_Cursor *c_2 = evas_object_textblock_cursor_new(tb); + evas_textblock_cursor_pos_set(c_2, pos_from + lenght); + /* delete replaced text, and make diff into redoundo module */ + redoundo_text_push(ed->rd, selection, pos_from, lenght, EINA_FALSE); + evas_textblock_cursor_range_delete(c_1, c_2); + + evas_textblock_cursor_free(c_1); + evas_textblock_cursor_free(c_2); + evas_textblock_cursor_pos_set(cur, old_pos); + + elm_entry_calc_force(ed->en_edit); + free(selection); +} + + static void edit_cursor_changed_manual_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h index 82638a8..8347dc7 100644 --- a/src/lib/enventor_private.h +++ b/src/lib/enventor_private.h @@ -277,5 +277,6 @@ void edit_selection_clear(edit_data *ed); Eina_Bool edit_redoundo(edit_data *ed, Eina_Bool undo); void edit_disabled_set(edit_data *ed, Eina_Bool disabled); void edit_error_set(edit_data *ed, int line, const char *target); +void edit_text_insert(edit_data *ed, const char *text); #endif diff --git a/src/lib/enventor_smart.c b/src/lib/enventor_smart.c index a7b9f12..11296e3 100644 --- a/src/lib/enventor_smart.c +++ b/src/lib/enventor_smart.c @@ -524,7 +524,7 @@ EOLIAN static void _enventor_object_text_insert(Eo *obj EINA_UNUSED, Enventor_Object_Data *pd, const char *text) { - elm_entry_entry_insert(edit_entry_get(pd->ed), text); + edit_text_insert(pd->ed, text); } EOLIAN static void --