elm_code: Fix selection when moving around with cursor keys
authorAndy Williams <andy@andywilliams.me>
Sat, 14 Jan 2017 19:39:39 +0000 (19:39 +0000)
committerAndy Williams <andy@andywilliams.me>
Sun, 15 Jan 2017 22:41:48 +0000 (22:41 +0000)
Also fix the handling of newlines in our selections
@fix

src/lib/elementary/elm_code_widget.c
src/lib/elementary/elm_code_widget_selection.c

index 7ce76de..6131fca 100644 (file)
@@ -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"))
index 9c73bdc..4a92b49 100644 (file)
@@ -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