summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2018-07-27 15:20:24 +0100
committerAndy Williams <andy@andywilliams.me>2018-07-27 17:08:44 +0100
commitad379ce04fa3dae4ef06c5f6211bc4b962cb3fa4 (patch)
tree4af883860573085f20773b35309cf08d30e18a22
parent49554b2b6c993aa2067e86a0eb158f47fc15c3f0 (diff)
elm_code_widget: fix keyboard and scrolling with active selection.
Summary: This adds some attributes to the selectiont type in elm_code. Including the type (whether it is mouse or keyboard) and also whether a selection is in progress. Thus we can reliably select around the file and also move/scroll when there is an active selection. Test Plan: Drag and select text with mouse. Also the same with keyboard (hold shift and select). Leave selection active and scroll around the file. The selection should remain and full movement is possible while retaining the active selection. This could really be refactored for a next major release. Reviewers: #committers, ajwillia.ms, cedric Reviewed By: ajwillia.ms Subscribers: zmike Tags: #efl Differential Revision: https://phab.enlightenment.org/D6676
-rw-r--r--src/lib/elementary/elm_code_widget.c27
-rw-r--r--src/lib/elementary/elm_code_widget_private.h12
-rw-r--r--src/lib/elementary/elm_code_widget_selection.c29
3 files changed, 67 insertions, 1 deletions
diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c
index 36e7ccfdf0..5157838667 100644
--- a/src/lib/elementary/elm_code_widget.c
+++ b/src/lib/elementary/elm_code_widget.c
@@ -344,6 +344,16 @@ _elm_code_widget_fill_cursor(Elm_Code_Widget *widget, unsigned int number, int g
344 if (pd->cursor_col + gutter - 1 >= (unsigned int) w) 344 if (pd->cursor_col + gutter - 1 >= (unsigned int) w)
345 return; 345 return;
346 346
347 if (pd->selection && !pd->selection->in_progress)
348 {
349 Elm_Code_Line *line = elm_code_file_line_get(pd->code->file, number);
350 if (!line)
351 return;
352
353 if (!elm_code_widget_line_visible_get(widget, line))
354 return;
355 }
356
347 _elm_code_widget_cursor_update(widget, pd); 357 _elm_code_widget_cursor_update(widget, pd);
348 } 358 }
349} 359}
@@ -451,6 +461,9 @@ _elm_code_widget_cursor_selection_set(Elm_Code_Widget *widget, Elm_Code_Widget_D
451 end_line = pd->selection->end_line; 461 end_line = pd->selection->end_line;
452 end_col = pd->selection->end_col; 462 end_col = pd->selection->end_col;
453 463
464 if (pd->selection->type == ELM_CODE_WIDGET_SELECTION_KEYBOARD)
465 return;
466
454 if ((pd->selection->start_line == pd->selection->end_line && pd->selection->end_col > pd->selection->start_col) || 467 if ((pd->selection->start_line == pd->selection->end_line && pd->selection->end_col > pd->selection->start_col) ||
455 (pd->selection->start_line < pd->selection->end_line)) 468 (pd->selection->start_line < pd->selection->end_line))
456 { 469 {
@@ -700,7 +713,8 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd,
700 pd->cursor_col = elm_code_widget_line_text_column_width_to_position(widget, line_obj, position); 713 pd->cursor_col = elm_code_widget_line_text_column_width_to_position(widget, line_obj, position);
701 714
702 efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget); 715 efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget);
703 _elm_code_widget_cursor_ensure_visible(widget); 716 if (!pd->selection || (pd->selection && pd->selection->in_progress))
717 _elm_code_widget_cursor_ensure_visible(widget);
704 718
705 if (oldrow != pd->cursor_line) 719 if (oldrow != pd->cursor_line)
706 _elm_code_widget_refresh(widget, line_obj); 720 _elm_code_widget_refresh(widget, line_obj);
@@ -1158,6 +1172,11 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj
1158 if (!pd->selection) 1172 if (!pd->selection)
1159 if (col > 0 && row <= elm_code_file_lines_get(pd->code->file)) 1173 if (col > 0 && row <= elm_code_file_lines_get(pd->code->file))
1160 elm_code_widget_selection_start(widget, row, col); 1174 elm_code_widget_selection_start(widget, row, col);
1175
1176 _elm_code_widget_selection_type_set(widget, ELM_CODE_WIDGET_SELECTION_MOUSE);
1177 _elm_code_widget_selection_in_progress_set(widget, EINA_TRUE);
1178
1179
1161 elm_code_widget_selection_end(widget, row, col); 1180 elm_code_widget_selection_end(widget, row, col);
1162} 1181}
1163 1182
@@ -1179,6 +1198,8 @@ _elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E
1179 1198
1180 if (pd->selection) 1199 if (pd->selection)
1181 { 1200 {
1201 _elm_code_widget_selection_in_progress_set(widget, EINA_FALSE);
1202
1182 if (pd->selection->start_line == pd->selection->end_line && 1203 if (pd->selection->start_line == pd->selection->end_line &&
1183 pd->selection->start_col == pd->selection->end_col) 1204 pd->selection->start_col == pd->selection->end_col)
1184 elm_code_widget_selection_clear(widget); 1205 elm_code_widget_selection_clear(widget);
@@ -1736,6 +1757,9 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
1736 if (!pd->selection) 1757 if (!pd->selection)
1737 elm_code_widget_selection_start(widget, pd->cursor_line, pd->cursor_col - (backwards?1:0)); 1758 elm_code_widget_selection_start(widget, pd->cursor_line, pd->cursor_col - (backwards?1:0));
1738 1759
1760 _elm_code_widget_selection_type_set(widget, ELM_CODE_WIDGET_SELECTION_KEYBOARD);
1761 _elm_code_widget_selection_in_progress_set(widget, EINA_TRUE);
1762
1739 if (pd->selection && pd->selection->start_line == pd->selection->end_line) 1763 if (pd->selection && pd->selection->start_line == pd->selection->end_line)
1740 { 1764 {
1741 if ((pd->selection->end_col == pd->selection->start_col && !backwards) || 1765 if ((pd->selection->end_col == pd->selection->start_col && !backwards) ||
@@ -1776,6 +1800,7 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
1776 adjust = (pd->selection->end_line > pd->selection->start_line); 1800 adjust = (pd->selection->end_line > pd->selection->start_line);
1777 1801
1778 elm_code_widget_selection_end(widget, pd->cursor_line, pd->cursor_col - (adjust?1:0)); 1802 elm_code_widget_selection_end(widget, pd->cursor_line, pd->cursor_col - (adjust?1:0));
1803 _elm_code_widget_selection_in_progress_set(widget, EINA_FALSE);
1779 } 1804 }
1780 } 1805 }
1781 1806
diff --git a/src/lib/elementary/elm_code_widget_private.h b/src/lib/elementary/elm_code_widget_private.h
index 21d652d97d..ec1e53dc35 100644
--- a/src/lib/elementary/elm_code_widget_private.h
+++ b/src/lib/elementary/elm_code_widget_private.h
@@ -4,10 +4,18 @@
4/** 4/**
5 * Structure holding the info about a selected region. 5 * Structure holding the info about a selected region.
6 */ 6 */
7typedef enum
8{
9 ELM_CODE_WIDGET_SELECTION_KEYBOARD,
10 ELM_CODE_WIDGET_SELECTION_MOUSE,
11} Elm_Code_Widget_Selection_Type;
12
7typedef struct 13typedef struct
8{ 14{
9 unsigned int start_line, end_line; 15 unsigned int start_line, end_line;
10 unsigned int start_col, end_col; 16 unsigned int start_col, end_col;
17 Elm_Code_Widget_Selection_Type type;
18 Eina_Bool in_progress;
11} Elm_Code_Widget_Selection_Data; 19} Elm_Code_Widget_Selection_Data;
12 20
13typedef struct 21typedef struct
@@ -68,4 +76,8 @@ void _elm_code_widget_undo_change_add(Evas_Object *widget, Elm_Code_Widget_Chang
68 76
69void _elm_code_widget_change_selection_add(Evas_Object *widget); 77void _elm_code_widget_change_selection_add(Evas_Object *widget);
70 78
79void _elm_code_widget_selection_in_progress_set(Evas_Object *widget, Eina_Bool state);
80
81void _elm_code_widget_selection_type_set(Evas_Object *widget, Elm_Code_Widget_Selection_Type type);
82
71#endif 83#endif
diff --git a/src/lib/elementary/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c
index 7111c42996..834c025e94 100644
--- a/src/lib/elementary/elm_code_widget_selection.c
+++ b/src/lib/elementary/elm_code_widget_selection.c
@@ -58,6 +58,8 @@ elm_code_widget_selection_start(Evas_Object *widget,
58 pd->selection = selection; 58 pd->selection = selection;
59 } 59 }
60 60
61 _elm_code_widget_selection_in_progress_set(widget, EINA_TRUE);
62
61 pd->selection->start_line = line; 63 pd->selection->start_line = line;
62 pd->selection->start_col = col; 64 pd->selection->start_col = col;
63 efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_START, widget); 65 efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_START, widget);
@@ -464,3 +466,30 @@ elm_code_widget_selection_is_empty(Evas_Object *widget)
464 466
465 return ret; 467 return ret;
466} 468}
469
470void
471_elm_code_widget_selection_in_progress_set(Evas_Object *widget, Eina_Bool state)
472{
473 Elm_Code_Widget_Data *pd;
474
475 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
476
477 if (!pd || !pd->selection)
478 return;
479
480 pd->selection->in_progress = state;
481}
482
483void
484_elm_code_widget_selection_type_set(Evas_Object *widget, Elm_Code_Widget_Selection_Type type)
485{
486 Elm_Code_Widget_Data *pd;
487
488 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
489
490 if (!pd || !pd->selection)
491 return;
492
493 pd->selection->type = type;
494}
495