diff options
author | Alastair Poole <netstar@gmail.com> | 2018-08-17 12:52:32 -0400 |
---|---|---|
committer | Mike Blumenkrantz <zmike@samsung.com> | 2018-08-17 12:52:32 -0400 |
commit | 0c4dc97c80867c4125ba541910d8f1d367962513 (patch) | |
tree | e1b88b4e351464a19fec40df63eed942e2e8b2c9 | |
parent | e14367331c2b13119df9745fbe434ab3672caeb3 (diff) | |
download | efl-0c4dc97c80867c4125ba541910d8f1d367962513.tar.gz |
elm_code: fix crash on backspace and selection delete.
Summary:
FIx backspace issue and also issue involving the cursor
position and deleting/cutting/backspace of selected text.
Now that we properly move the cursor around when making a
selection, it's important that we place the cursor in a
valid position in the widget following the removal of text.
Previously the cursor always remained in a "safe" position
however now it's crucial to update this position when
necessary.
@fix T7259
Test Plan:
Use backspace into new lines in an elm_code widget.
Make selections with the mouse or keyboard. Delete/cut these selections.
The cursor should be positioned correctly and also visible.
Reviewers: #committers, ajwillia.ms, zmike
Reviewed By: zmike
Subscribers: cedric, #reviewers
Tags: #efl
Maniphest Tasks: T7259
Differential Revision: https://phab.enlightenment.org/D6835
-rw-r--r-- | src/lib/elementary/elm_code_widget.c | 15 | ||||
-rw-r--r-- | src/lib/elementary/elm_code_widget_selection.c | 8 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c index 600a9b786c..1c315f047d 100644 --- a/src/lib/elementary/elm_code_widget.c +++ b/src/lib/elementary/elm_code_widget.c @@ -1558,7 +1558,7 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) { Elm_Code *code; Elm_Code_Line *line, *oldline; - unsigned int row, col, oldlength, position; + unsigned int row, col, oldlength, position = 0; code = elm_obj_code_widget_code_get(widget); elm_obj_code_widget_cursor_position_get(widget, &row, &col); @@ -1584,8 +1584,19 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) elm_code_line_merge_up(line); } + elm_code_widget_selection_clear(widget); -// TODO construct and pass a change object + + line = elm_code_file_line_get(code->file, row - 1); + if (line) + { + if (position) + elm_code_widget_cursor_position_set(widget, row - 1, position); + else + elm_code_widget_cursor_position_set(widget, row - 1, line->length + 1); + } + + // TODO construct and pass a change object efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); } diff --git a/src/lib/elementary/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c index 834c025e94..cf5f355009 100644 --- a/src/lib/elementary/elm_code_widget_selection.c +++ b/src/lib/elementary/elm_code_widget_selection.c @@ -251,26 +251,32 @@ _elm_code_widget_selection_delete_do(Evas_Object *widget, Eina_Bool undo) { Elm_Code_Widget_Data *pd; Elm_Code_Widget_Selection_Data *selection; + unsigned int row, col; pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->selection) return; + if (undo) _elm_code_widget_change_selection_add(widget); selection = elm_code_widget_selection_normalized_get(widget); + + row = selection->start_line; + col = selection->start_col; + if (selection->start_line == selection->end_line) _elm_code_widget_selection_delete_single(widget, pd); else _elm_code_widget_selection_delete_multi(widget, pd); - elm_code_widget_cursor_position_set(widget, selection->start_line, selection->start_col); free(pd->selection); pd->selection = NULL; free(selection); efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); + elm_code_widget_cursor_position_set(widget, row, col); } EAPI void |