summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYeongJong Lee <cleanlyj@naver.com>2017-01-31 19:04:33 +0000
committerAndy Williams <andy@andywilliams.me>2017-01-31 19:40:20 +0000
commit928091bedbcb1bb3166f680bcd192ef32677fc3b (patch)
treec30c1b6ac8d49530b6482c9193d539e03ec22bb4
parente483e35f3dd898085eadf1f70a94e80bbd987759 (diff)
elm_code: fix that selected code can't undo
Summary: Change some undo logic and remove unused function Test Plan: 1. elementary_test - Code Editor 2. Select lines. 3. Remove selected lines. 4. undo removed lines(<Ctrl> + <z>) Reviewers: ajwillia.ms Reviewed By: ajwillia.ms Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D4631
-rw-r--r--src/lib/elementary/elm_code_widget.c83
-rw-r--r--src/lib/elementary/elm_code_widget_selection.c23
-rw-r--r--src/lib/elementary/elm_code_widget_selection.h2
-rw-r--r--src/lib/elementary/elm_code_widget_undo.c37
4 files changed, 118 insertions, 27 deletions
diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c
index 98799d5f49..6d17db2baa 100644
--- a/src/lib/elementary/elm_code_widget.c
+++ b/src/lib/elementary/elm_code_widget.c
@@ -1206,25 +1206,6 @@ _elm_code_widget_cursor_move_pagedown(Elm_Code_Widget *widget)
1206 _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); 1206 _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE);
1207} 1207}
1208 1208
1209static Eina_Bool
1210_elm_code_widget_delete_selection(Elm_Code_Widget *widget)
1211{
1212 Elm_Code_Widget_Data *pd;
1213 Elm_Code_Widget_Selection_Data *selection;
1214
1215 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
1216
1217 if (!pd->selection)
1218 return EINA_FALSE;
1219
1220 selection = elm_code_widget_selection_normalized_get(widget);
1221 elm_code_widget_selection_delete(widget);
1222 elm_code_widget_cursor_position_set(widget, selection->start_line, selection->start_col);
1223 free(selection);
1224
1225 return EINA_TRUE;
1226}
1227
1228static Elm_Code_Widget_Change_Info * 1209static Elm_Code_Widget_Change_Info *
1229_elm_code_widget_change_create(unsigned int start_col, unsigned int start_line, 1210_elm_code_widget_change_create(unsigned int start_col, unsigned int start_line,
1230 unsigned int end_col, unsigned int end_line, 1211 unsigned int end_col, unsigned int end_line,
@@ -1256,6 +1237,32 @@ _elm_code_widget_change_free(Elm_Code_Widget_Change_Info *info)
1256} 1237}
1257 1238
1258void 1239void
1240_elm_code_widget_change_selection_add(Evas_Object *widget)
1241{
1242 Elm_Code_Widget_Change_Info *change;
1243 Elm_Code_Widget_Selection_Data *selection;
1244 char *selection_text;
1245
1246 if (elm_code_widget_selection_is_empty(widget))
1247 return;
1248
1249 selection_text = elm_code_widget_selection_text_get(widget);
1250 selection = elm_code_widget_selection_normalized_get(widget);
1251
1252 change = _elm_code_widget_change_create(selection->start_col,
1253 selection->start_line,
1254 selection->end_col,
1255 selection->end_line,
1256 selection_text,
1257 strlen(selection_text),
1258 EINA_FALSE);
1259 _elm_code_widget_undo_change_add(widget, change);
1260 _elm_code_widget_change_free(change);
1261 free(selection_text);
1262 free(selection);
1263}
1264
1265void
1259_elm_code_widget_text_at_cursor_insert_do(Elm_Code_Widget *widget, const char *text, int length, Eina_Bool undo) 1266_elm_code_widget_text_at_cursor_insert_do(Elm_Code_Widget *widget, const char *text, int length, Eina_Bool undo)
1260{ 1267{
1261 Elm_Code *code; 1268 Elm_Code *code;
@@ -1264,7 +1271,12 @@ _elm_code_widget_text_at_cursor_insert_do(Elm_Code_Widget *widget, const char *t
1264 unsigned int row, col, position, col_width, curlen, indent; 1271 unsigned int row, col, position, col_width, curlen, indent;
1265 const char *curtext, *indent_text; 1272 const char *curtext, *indent_text;
1266 1273
1267 _elm_code_widget_delete_selection(widget); 1274 if (undo)
1275 {
1276 _elm_code_widget_change_selection_add(widget);
1277 elm_code_widget_selection_delete(widget);
1278 }
1279
1268 code = elm_obj_code_widget_code_get(widget); 1280 code = elm_obj_code_widget_code_get(widget);
1269 elm_obj_code_widget_cursor_position_get(widget, &row, &col); 1281 elm_obj_code_widget_cursor_position_get(widget, &row, &col);
1270 line = elm_code_file_line_get(code->file, row); 1282 line = elm_code_file_line_get(code->file, row);
@@ -1353,7 +1365,9 @@ _elm_code_widget_newline(Elm_Code_Widget *widget)
1353 unsigned int row, col, position, oldlen, width, indent; 1365 unsigned int row, col, position, oldlen, width, indent;
1354 char *oldtext, *leading; 1366 char *oldtext, *leading;
1355 1367
1356 _elm_code_widget_delete_selection(widget); 1368 _elm_code_widget_change_selection_add(widget);
1369 elm_code_widget_selection_delete(widget);
1370
1357 code = elm_obj_code_widget_code_get(widget); 1371 code = elm_obj_code_widget_code_get(widget);
1358 elm_obj_code_widget_cursor_position_get(widget, &row, &col); 1372 elm_obj_code_widget_cursor_position_get(widget, &row, &col);
1359 line = elm_code_file_line_get(code->file, row); 1373 line = elm_code_file_line_get(code->file, row);
@@ -1400,18 +1414,27 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline)
1400 1414
1401 if (nextline) 1415 if (nextline)
1402 { 1416 {
1417 elm_code_widget_selection_start(widget, row, col);
1418 elm_code_widget_selection_end(widget, row + 1, 0);
1419 _elm_code_widget_change_selection_add(widget);
1420
1403 elm_code_line_merge_down(line); 1421 elm_code_line_merge_down(line);
1404 } 1422 }
1405 else 1423 else
1406 { 1424 {
1407 oldline = elm_code_file_line_get(code->file, row - 1); 1425 oldline = elm_code_file_line_get(code->file, row - 1);
1408 elm_code_line_text_get(oldline, &oldlength); 1426 elm_code_line_text_get(oldline, &oldlength);
1409 elm_code_line_merge_up(line);
1410 1427
1411 position = elm_code_widget_line_text_column_width_to_position(widget, oldline, oldlength); 1428 position = elm_code_widget_line_text_column_width_to_position(widget, oldline, oldlength);
1429 elm_code_widget_selection_start(widget, row - 1, position);
1430 elm_code_widget_selection_end(widget, row, 0);
1431 _elm_code_widget_change_selection_add(widget);
1432
1433 elm_code_line_merge_up(line);
1412 1434
1413 elm_obj_code_widget_cursor_position_set(widget, row - 1, position); 1435 elm_obj_code_widget_cursor_position_set(widget, row - 1, position);
1414 } 1436 }
1437 elm_code_widget_selection_clear(widget);
1415// TODO construct and pass a change object 1438// TODO construct and pass a change object
1416 efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); 1439 efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
1417} 1440}
@@ -1425,8 +1448,12 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget)
1425 unsigned int row, col, position, start_col, end_col, char_width; 1448 unsigned int row, col, position, start_col, end_col, char_width;
1426 const char *text; 1449 const char *text;
1427 1450
1428 if (_elm_code_widget_delete_selection(widget)) 1451 if (!elm_code_widget_selection_is_empty(widget))
1429 return; // TODO fire the change and log it 1452 {
1453 _elm_code_widget_change_selection_add(widget);
1454 elm_code_widget_selection_delete(widget);
1455 return;
1456 }
1430 1457
1431 code = elm_obj_code_widget_code_get(widget); 1458 code = elm_obj_code_widget_code_get(widget);
1432 elm_obj_code_widget_cursor_position_get(widget, &row, &col); 1459 elm_obj_code_widget_cursor_position_get(widget, &row, &col);
@@ -1468,8 +1495,12 @@ _elm_code_widget_delete(Elm_Code_Widget *widget)
1468 unsigned int row, col, position, char_width, start_col, end_col; 1495 unsigned int row, col, position, char_width, start_col, end_col;
1469 const char *text; 1496 const char *text;
1470 1497
1471 if (_elm_code_widget_delete_selection(widget)) 1498 if (!elm_code_widget_selection_is_empty(widget))
1472 return; // TODO fire the change and log it 1499 {
1500 _elm_code_widget_change_selection_add(widget);
1501 elm_code_widget_selection_delete(widget);
1502 return;
1503 }
1473 1504
1474 code = elm_obj_code_widget_code_get(widget); 1505 code = elm_obj_code_widget_code_get(widget);
1475 elm_obj_code_widget_cursor_position_get(widget, &row, &col); 1506 elm_obj_code_widget_cursor_position_get(widget, &row, &col);
diff --git a/src/lib/elementary/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c
index 4a92b49eba..6f4357f1e5 100644
--- a/src/lib/elementary/elm_code_widget_selection.c
+++ b/src/lib/elementary/elm_code_widget_selection.c
@@ -459,3 +459,26 @@ elm_code_widget_selection_paste(Evas_Object *widget)
459 459
460 elm_cnp_selection_get(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, _selection_paste_cb, widget); 460 elm_cnp_selection_get(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, _selection_paste_cb, widget);
461} 461}
462
463EAPI Eina_Bool
464elm_code_widget_selection_is_empty(Evas_Object *widget)
465{
466 Elm_Code_Widget_Data *pd;
467 Elm_Code_Widget_Selection_Data *selection;
468 Eina_Bool ret = EINA_FALSE;
469
470 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
471
472 if (!pd->selection)
473 return EINA_TRUE;
474
475 selection = elm_code_widget_selection_normalized_get(widget);
476
477 if (selection->start_col == selection->end_col &&
478 selection->start_line == selection->end_line)
479 ret = EINA_TRUE;
480
481 free(selection);
482
483 return ret;
484}
diff --git a/src/lib/elementary/elm_code_widget_selection.h b/src/lib/elementary/elm_code_widget_selection.h
index b79abc763f..9fe7e5c588 100644
--- a/src/lib/elementary/elm_code_widget_selection.h
+++ b/src/lib/elementary/elm_code_widget_selection.h
@@ -33,6 +33,8 @@ EAPI void elm_code_widget_selection_cut(Evas_Object *widget);
33EAPI void elm_code_widget_selection_copy(Evas_Object *widget); 33EAPI void elm_code_widget_selection_copy(Evas_Object *widget);
34EAPI void elm_code_widget_selection_paste(Evas_Object *widget); 34EAPI void elm_code_widget_selection_paste(Evas_Object *widget);
35 35
36EAPI Eina_Bool elm_code_widget_selection_is_empty(Evas_Object *widget);
37
36/** 38/**
37 * @} 39 * @}
38 */ 40 */
diff --git a/src/lib/elementary/elm_code_widget_undo.c b/src/lib/elementary/elm_code_widget_undo.c
index d7806edc15..ed0b8f2f01 100644
--- a/src/lib/elementary/elm_code_widget_undo.c
+++ b/src/lib/elementary/elm_code_widget_undo.c
@@ -37,6 +37,12 @@ static void
37_elm_code_widget_undo_change(Evas_Object *widget, 37_elm_code_widget_undo_change(Evas_Object *widget,
38 Elm_Code_Widget_Change_Info *info) 38 Elm_Code_Widget_Change_Info *info)
39{ 39{
40 Elm_Code_Widget_Data *pd;
41 unsigned int textlen, position, row, col;
42 short nllen;
43 Elm_Code_Line *line;
44 pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
45
40 if (info->insert) 46 if (info->insert)
41 { 47 {
42 elm_code_widget_selection_start(widget, info->start_line, info->start_col); 48 elm_code_widget_selection_start(widget, info->start_line, info->start_col);
@@ -45,8 +51,37 @@ _elm_code_widget_undo_change(Evas_Object *widget,
45 } 51 }
46 else 52 else
47 { 53 {
54 elm_code_widget_selection_clear(widget);
48 elm_code_widget_cursor_position_set(widget, info->start_line, info->start_col); 55 elm_code_widget_cursor_position_set(widget, info->start_line, info->start_col);
49 _elm_code_widget_text_at_cursor_insert_no_undo(widget, info->content, info->length); 56 unsigned int newrow = info->start_line;
57 while (newrow <= info->end_line)
58 {
59 line = elm_code_file_line_get(pd->code->file, newrow);
60 if (newrow != info->end_line)
61 {
62 textlen = info->length;
63 textlen = elm_code_text_newlinenpos(info->content, info->length, &nllen);
64 info->length -= textlen + nllen;
65 _elm_code_widget_text_at_cursor_insert_no_undo(widget,
66 info->content,
67 textlen);
68 elm_obj_code_widget_cursor_position_get(widget, &row, &col);
69 position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
70 elm_code_line_split_at(line, position);
71 elm_code_widget_cursor_position_set(widget, newrow + 1, 1);
72 info->content += textlen + nllen;
73 }
74 else
75 {
76 _elm_code_widget_text_at_cursor_insert_no_undo(widget,
77 info->content,
78 info->length);
79 }
80 newrow++;
81 }
82 if (info->end_col < 1)
83 info->end_col = 1;
84 elm_code_widget_cursor_position_set(widget, info->end_line, info->end_col);
50 } 85 }
51} 86}
52 87