From: Andy Williams Date: Sat, 14 Jan 2017 19:39:39 +0000 (+0000) Subject: elm_code: Fix selection when moving around with cursor keys X-Git-Tag: upstream/1.20.0~2445 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d86143212a26d7dda5df27f758a2d610435c1bb8;p=platform%2Fupstream%2Fefl.git elm_code: Fix selection when moving around with cursor keys Also fix the handling of newlines in our selections @fix --- diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c index 7ce76de..6131fca 100644 --- a/src/lib/elementary/elm_code_widget.c +++ b/src/lib/elementary/elm_code_widget.c @@ -1542,7 +1542,7 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; - Eina_Bool shift; + Eina_Bool shift, adjust, backwards = EINA_FALSE; widget = (Elm_Code_Widget *)data; pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -1571,8 +1571,11 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, { if (shift) { + backwards = !strcmp(ev->key, "Up") || !strcmp(ev->key, "Left") || + !strcmp(ev->key, "Home") || !strcmp(ev->key, "Prior"); + if (!pd->selection) - elm_code_widget_selection_start(widget, pd->cursor_line, pd->cursor_col); + elm_code_widget_selection_start(widget, pd->cursor_line, pd->cursor_col - (backwards?1:0)); } else elm_code_widget_selection_clear(widget); @@ -1595,7 +1598,15 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_cursor_move_pagedown(widget); if (shift) - elm_code_widget_selection_end(widget, pd->cursor_line, pd->cursor_col); + { + if (pd->selection->start_line == pd->selection->end_line) + adjust = (pd->selection->end_col > pd->selection->start_col) || + (!backwards && (pd->selection->end_col == pd->selection->start_col)); + else + adjust = (pd->selection->end_line > pd->selection->start_line); + + elm_code_widget_selection_end(widget, pd->cursor_line, pd->cursor_col - (adjust?1:0)); + } } else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return")) diff --git a/src/lib/elementary/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c index 9c73bdc..4a92b49 100644 --- a/src/lib/elementary/elm_code_widget_selection.c +++ b/src/lib/elementary/elm_code_widget_selection.c @@ -36,8 +36,6 @@ _elm_code_widget_selection_limit(Evas_Object *widget EINA_UNUSED, Elm_Code_Widge if (*col > width + 1) *col = width + 1; - if (*col < 1) - *col = 1; } EAPI void @@ -63,7 +61,6 @@ elm_code_widget_selection_start(Evas_Object *widget, pd->selection->start_line = line; pd->selection->start_col = col; efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); - elm_obj_code_widget_cursor_position_set(widget, line, col); } EAPI void