forked from enlightenment/enventor
search - fixed missing of a next word selection.
This is a side effect of partial syntax color updation. Apply syntax color full updation if search mode is enabled. and whenever word is replaced, repeat the syntax color full updation again.
This commit is contained in:
parent
0cd86f1289
commit
4e8e915cbe
|
@ -28,6 +28,7 @@ struct editor_s
|
|||
|
||||
int cur_line;
|
||||
int line_max;
|
||||
int syntax_color_lock;
|
||||
Evas_Coord scroller_h;
|
||||
|
||||
Ecore_Timer *syntax_color_timer;
|
||||
|
@ -40,7 +41,6 @@ struct editor_s
|
|||
Eina_Bool edit_changed : 1;
|
||||
Eina_Bool linenumber : 1;
|
||||
Eina_Bool ctrl_pressed : 1;
|
||||
Eina_Bool on_drag : 1;
|
||||
};
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -117,16 +117,18 @@ visible_text_region_get(edit_data *ed, int *from_line, int *to_line)
|
|||
}
|
||||
|
||||
static void
|
||||
syntax_color_apply(edit_data *ed)
|
||||
syntax_color_apply(edit_data *ed, Eina_Bool partial)
|
||||
{
|
||||
Evas_Object *tb = elm_entry_textblock_get(ed->en_edit);
|
||||
char *text = (char *) evas_object_textblock_text_markup_get(tb);
|
||||
int pos = elm_entry_cursor_pos_get(ed->en_edit);
|
||||
|
||||
int from_line, to_line;
|
||||
visible_text_region_get(ed, &from_line, &to_line);
|
||||
int from_line = 1;
|
||||
int to_line = -1;
|
||||
if (partial) visible_text_region_get(ed, &from_line, &to_line);
|
||||
|
||||
char *from, *to;
|
||||
char *from = NULL;
|
||||
char *to = NULL;
|
||||
char *utf8 = (char *) color_cancel(syntax_color_data_get(ed->sh), text,
|
||||
strlen(text), from_line, to_line, &from,
|
||||
&to);
|
||||
|
@ -154,7 +156,7 @@ syntax_color_timer_cb(void *data)
|
|||
{
|
||||
edit_data *ed = data;
|
||||
if (!color_ready(syntax_color_data_get(ed->sh))) return ECORE_CALLBACK_RENEW;
|
||||
syntax_color_apply(ed);
|
||||
syntax_color_apply(ed, EINA_TRUE);
|
||||
ed->syntax_color_timer = NULL;
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
@ -162,7 +164,9 @@ syntax_color_timer_cb(void *data)
|
|||
static void
|
||||
syntax_color_partial_update(edit_data *ed, double time)
|
||||
{
|
||||
if (ed->on_drag) return;
|
||||
/* If the syntax_color_full_update is requested forcely, lock would be -1
|
||||
in this case, it should avoid partial updation by entry changed. */
|
||||
if (ed->syntax_color_lock != 0) return;
|
||||
ecore_thread_cancel(ed->syntax_color_thread);
|
||||
ed->syntax_color_thread = NULL;
|
||||
ecore_timer_del(ed->syntax_color_timer);
|
||||
|
@ -215,20 +219,30 @@ syntax_color_thread_cancel_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
|
|||
free(td);
|
||||
}
|
||||
|
||||
static void
|
||||
syntax_color_full_update(edit_data *ed)
|
||||
void
|
||||
syntax_color_full_update(edit_data *ed, Eina_Bool thread)
|
||||
{
|
||||
if (ed->syntax_color_lock > 0) return;
|
||||
|
||||
ecore_timer_del(ed->syntax_color_timer);
|
||||
ed->syntax_color_timer = NULL;
|
||||
|
||||
syntax_color_td *td = malloc(sizeof(syntax_color_td));
|
||||
td->ed = ed;
|
||||
Evas_Object *tb = elm_entry_textblock_get(ed->en_edit);
|
||||
td->text = (char *) evas_object_textblock_text_markup_get(tb);
|
||||
ed->syntax_color_thread = ecore_thread_run(syntax_color_thread_cb,
|
||||
syntax_color_thread_end_cb,
|
||||
syntax_color_thread_cancel_cb,
|
||||
td);
|
||||
if (thread)
|
||||
{
|
||||
syntax_color_td *td = malloc(sizeof(syntax_color_td));
|
||||
td->ed = ed;
|
||||
Evas_Object *tb = elm_entry_textblock_get(ed->en_edit);
|
||||
td->text = (char *) evas_object_textblock_text_markup_get(tb);
|
||||
ed->syntax_color_thread =
|
||||
ecore_thread_run(syntax_color_thread_cb,
|
||||
syntax_color_thread_end_cb,
|
||||
syntax_color_thread_cancel_cb,
|
||||
td);
|
||||
}
|
||||
else
|
||||
{
|
||||
syntax_color_apply(ed, EINA_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -364,6 +378,29 @@ ctxpopup_preview_dismiss_cb(void *data, Evas_Object *obj,
|
|||
elm_object_focus_set(ed->en_edit, EINA_TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
edit_syntax_color_full_apply(edit_data *ed, Eina_Bool force)
|
||||
{
|
||||
int lock;
|
||||
|
||||
if (force)
|
||||
{
|
||||
lock = ed->syntax_color_lock;
|
||||
ed->syntax_color_lock = -1;
|
||||
}
|
||||
syntax_color_full_update(ed, EINA_FALSE);
|
||||
|
||||
if (force) ed->syntax_color_lock = lock;
|
||||
else ed->syntax_color_lock++;
|
||||
}
|
||||
|
||||
void
|
||||
edit_syntax_color_partial_apply(edit_data *ed)
|
||||
{
|
||||
ed->syntax_color_lock--;
|
||||
syntax_color_partial_update(ed, SYNTAX_COLOR_DEFAULT_TIME);
|
||||
}
|
||||
|
||||
void
|
||||
edit_template_insert(edit_data *ed)
|
||||
{
|
||||
|
@ -885,8 +922,8 @@ scroller_vbar_press_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
edit_data *ed = data;
|
||||
ed->on_drag = EINA_TRUE;
|
||||
syntax_color_full_update(ed);
|
||||
syntax_color_full_update(ed, EINA_TRUE);
|
||||
ed->syntax_color_lock++;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -894,7 +931,7 @@ scroller_vbar_unpress_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
edit_data *ed = data;
|
||||
ed->on_drag = EINA_FALSE;
|
||||
ed->syntax_color_lock--;
|
||||
syntax_color_partial_update(ed, SYNTAX_COLOR_SHORT_TIME);
|
||||
}
|
||||
|
||||
|
@ -967,8 +1004,6 @@ edit_init(Evas_Object *parent)
|
|||
elm_object_focus_set(en_edit, EINA_TRUE);
|
||||
elm_object_part_content_set(layout, "elm.swallow.edit", en_edit);
|
||||
|
||||
search_entry_register(en_edit);
|
||||
|
||||
ed->scroller = scroller;
|
||||
ed->en_line = en_line;
|
||||
ed->en_edit = en_edit;
|
||||
|
@ -1200,3 +1235,9 @@ edit_goto(edit_data *ed, int line)
|
|||
elm_entry_calc_force(ed->en_edit);
|
||||
elm_object_focus_set(ed->en_edit, EINA_TRUE);
|
||||
}
|
||||
|
||||
Evas_Object *
|
||||
edit_entry_get(edit_data *ed)
|
||||
{
|
||||
return ed->en_edit;
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ ctrl_func(app_data *ad, const char *key)
|
|||
//Find/Replace
|
||||
if (!strcmp(key, "f") || !strcmp(key, "F"))
|
||||
{
|
||||
search_open();
|
||||
search_open(ad->ed);
|
||||
return ECORE_CALLBACK_DONE;
|
||||
}
|
||||
//Goto Line
|
||||
|
|
|
@ -8,12 +8,14 @@ typedef struct search_s
|
|||
Evas_Object *en_find;
|
||||
Evas_Object *en_replace;
|
||||
Evas_Object *entry;
|
||||
edit_data *ed;
|
||||
int pos;
|
||||
int len;
|
||||
int syntax_color;
|
||||
Eina_Bool forward : 1;
|
||||
} search_data;
|
||||
|
||||
static search_data *g_sd = NULL;
|
||||
static Evas_Object *g_entry = NULL;
|
||||
static Evas_Coord win_x = -1;
|
||||
static Evas_Coord win_y = -1;
|
||||
static Evas_Coord win_w = DEFAULT_SEARCH_WIN_W;
|
||||
|
@ -80,6 +82,16 @@ replace_all_proc(search_data *sd)
|
|||
free(utf8);
|
||||
}
|
||||
|
||||
/* FIXME: selection_region_set() won't be worked all just right after entry
|
||||
changes, no idea why? so use the animator. */
|
||||
static Eina_Bool
|
||||
selection_region_anim_cb(void *data)
|
||||
{
|
||||
search_data *sd = data;
|
||||
elm_entry_select_region_set(sd->entry, sd->pos, sd->pos + sd->len);
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
static void
|
||||
find_forward_proc(search_data *sd)
|
||||
{
|
||||
|
@ -121,10 +133,9 @@ find_forward_proc(search_data *sd)
|
|||
}
|
||||
|
||||
//Got you!
|
||||
int len = strlen(find);
|
||||
sd->len = strlen(find);
|
||||
sd->pos = s - utf8;
|
||||
elm_entry_select_none(sd->entry);
|
||||
elm_entry_select_region_set(sd->entry, sd->pos, sd->pos + len);
|
||||
ecore_animator_add(selection_region_anim_cb, sd);
|
||||
free(utf8);
|
||||
}
|
||||
|
||||
|
@ -183,8 +194,8 @@ find_backward_proc(search_data *sd)
|
|||
|
||||
//Got you!
|
||||
sd->pos = prev - utf8;
|
||||
elm_entry_select_none(sd->entry);
|
||||
elm_entry_select_region_set(sd->entry, sd->pos, sd->pos + strlen(find));
|
||||
sd->len = strlen(find);
|
||||
ecore_animator_add(selection_region_anim_cb, sd);
|
||||
|
||||
free(utf8);
|
||||
}
|
||||
|
@ -220,6 +231,7 @@ replace_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
search_data *sd = data;
|
||||
Eina_Bool next;
|
||||
next = replace_proc(sd);
|
||||
edit_syntax_color_full_apply(sd->ed, EINA_TRUE);
|
||||
if (!next) return;
|
||||
if (sd->forward) find_forward_proc(sd);
|
||||
else find_backward_proc(sd);
|
||||
|
@ -231,6 +243,7 @@ replace_all_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
{
|
||||
search_data *sd = data;
|
||||
replace_all_proc(sd);
|
||||
edit_syntax_color_full_apply(sd->ed, EINA_TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -259,13 +272,30 @@ replace_activated_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
search_data *sd = data;
|
||||
Eina_Bool next;
|
||||
next = replace_proc(sd);
|
||||
edit_syntax_color_full_apply(sd->ed, EINA_TRUE);
|
||||
if (!next) return;
|
||||
if (sd->forward) find_forward_proc(sd);
|
||||
else find_backward_proc(sd);
|
||||
}
|
||||
|
||||
static void
|
||||
win_focused_cb(void *data, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
search_data *sd = g_sd;
|
||||
edit_syntax_color_full_apply(sd->ed, EINA_FALSE);
|
||||
sd->syntax_color++;
|
||||
}
|
||||
|
||||
static void
|
||||
win_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
search_data *sd = g_sd;
|
||||
edit_syntax_color_partial_apply(sd->ed);
|
||||
sd->syntax_color--;
|
||||
}
|
||||
|
||||
void
|
||||
search_open()
|
||||
search_open(edit_data *ed)
|
||||
{
|
||||
search_data *sd = g_sd;
|
||||
|
||||
|
@ -289,6 +319,8 @@ search_open()
|
|||
evas_object_smart_callback_add(win, "delete,request", win_delete_request_cb,
|
||||
sd);
|
||||
evas_object_smart_callback_add(win, "moved", win_moved_cb, sd);
|
||||
evas_object_smart_callback_add(win, "focused", win_focused_cb, sd);
|
||||
evas_object_smart_callback_add(win, "unfocused", win_unfocused_cb, sd);
|
||||
|
||||
//Bg
|
||||
Evas_Object *bg = elm_bg_add(win);
|
||||
|
@ -356,10 +388,11 @@ search_open()
|
|||
evas_object_show(win);
|
||||
|
||||
sd->win = win;
|
||||
sd->ed = ed;
|
||||
sd->layout = layout;
|
||||
sd->en_find = entry_find;
|
||||
sd->en_replace = entry_replace;
|
||||
sd->entry = g_entry;
|
||||
sd->entry = edit_entry_get(ed);
|
||||
sd->pos = -1;
|
||||
sd->forward = EINA_TRUE;
|
||||
}
|
||||
|
@ -371,17 +404,18 @@ search_is_opened()
|
|||
return (sd ? EINA_TRUE : EINA_FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
search_entry_register(Evas_Object *entry)
|
||||
{
|
||||
g_entry = entry;
|
||||
}
|
||||
|
||||
void
|
||||
search_close()
|
||||
{
|
||||
search_data *sd = g_sd;
|
||||
if (!sd) return;
|
||||
|
||||
while (sd->syntax_color > 0)
|
||||
{
|
||||
edit_syntax_color_partial_apply(sd->ed);
|
||||
sd->syntax_color--;
|
||||
}
|
||||
|
||||
//Save last state
|
||||
evas_object_geometry_get(sd->win, NULL, NULL, &win_w, &win_h);
|
||||
elm_win_screen_position_get(sd->win, &win_x, &win_y);
|
||||
|
|
|
@ -21,3 +21,6 @@ Eina_Stringshare *edit_cur_prog_name_get(edit_data *ed);
|
|||
Eina_Stringshare *edit_cur_part_name_get(edit_data *ed);
|
||||
int edit_max_line_get(edit_data *ed);
|
||||
void edit_goto(edit_data *ed, int line);
|
||||
void edit_syntax_color_full_apply(edit_data *ed, Eina_Bool force);
|
||||
void edit_syntax_color_partial_apply(edit_data *ed);
|
||||
Evas_Object * edit_entry_get(edit_data *ed);
|
||||
|
|
|
@ -2,5 +2,4 @@
|
|||
#define DEFAULT_SEARCH_WIN_H 90
|
||||
void search_open();
|
||||
void search_close();
|
||||
void search_entry_register(Evas_Object *entry);
|
||||
Eina_Bool search_is_opened();
|
||||
|
|
Loading…
Reference in New Issue