From 46d1017df7046e553871409ab507a8bc7f0fd5e6 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Thu, 12 Feb 2015 23:01:37 +0900 Subject: [PATCH] template: Fix cursor position when insert image description and textblock style. Fix the cursor position when image description and textblock style are inserted with image part and textblock part. --- src/lib/template.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/lib/template.c b/src/lib/template.c index 9d930b4..46fc16a 100644 --- a/src/lib/template.c +++ b/src/lib/template.c @@ -34,21 +34,24 @@ image_description_add(edit_data *ed) Eina_Bool images_block = parser_images_pos_get(edit_entry, &cursor_pos); if (cursor_pos == -1) return; + + elm_entry_cursor_pos_set(edit_entry, cursor_pos); + elm_entry_cursor_line_begin_set(edit_entry); + int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry); + int cursor_pos2; if (images_block) - { - elm_entry_cursor_pos_set(edit_entry, cursor_pos); - template_insert(ed, ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT, NULL, 0); - } + { + template_insert(ed, ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT, NULL, 0); + cursor_pos2 = elm_entry_cursor_pos_get(edit_entry); + } else - { - elm_entry_cursor_pos_set(edit_entry, cursor_pos); - elm_entry_cursor_line_begin_set(edit_entry); - int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry); - elm_entry_entry_insert(edit_entry, TEMPLATE_IMG_BLOCK); - edit_line_increase(ed, TEMPLATE_IMG_BLOCK_LINE_CNT); - int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry); - edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2); - } + { + elm_entry_entry_insert(edit_entry, TEMPLATE_IMG_BLOCK); + edit_line_increase(ed, TEMPLATE_IMG_BLOCK_LINE_CNT); + cursor_pos2 = elm_entry_cursor_pos_get(edit_entry); + edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2); + } + cursor_pos_to_restore += (cursor_pos2 - cursor_pos1); elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore); } @@ -84,6 +87,7 @@ textblock_style_add(edit_data *ed, const char *style_name) int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry); edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2); + cursor_pos_to_restore += (cursor_pos2 - cursor_pos1); elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore); } @@ -326,6 +330,9 @@ template_insert(edit_data *ed, Enventor_Template_Insert_Type insert_type, int cursor_pos2 = elm_entry_cursor_pos_get(entry); edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2); + if (!strcmp(paragh, "images")) + cursor_pos += (cursor_pos2 - cursor_pos1); + elm_entry_cursor_pos_set(entry, cursor_pos); edit_syntax_color_partial_apply(ed, 0);