stefan pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=0f21b1f7aaac18ba2ed3d10a6ff73f2db409c3bd

commit 0f21b1f7aaac18ba2ed3d10a6ff73f2db409c3bd
Author: Alastair Poole <[email protected]>
Date:   Fri Aug 17 11:37:59 2018 +0000

    elm_code: fix crash on backspace and selection delete.
    
    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
    Differential Revision: https://phab.enlightenment.org/D6835
---
 src/lib/elementary/elm_code_widget.c           | 15 +++++++++++++--
 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

-- 


Reply via email to