{
Elm_Code_Line *line;
const char *first, *last;
- unsigned int last_length, start, end, length, i;
+ unsigned int last_length, start, length, i;
+ int end;
char *content;
Elm_Code_Widget_Selection_Data *selection;
line = elm_code_file_line_get(pd->code->file, selection->end_line);
last = elm_code_line_text_get(line, &last_length);
- end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col);
+ end = (int)elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col);
- if (last_length == end)
- {
- length = start + last_length - end;
- content = malloc(sizeof(char) * length);
- strncpy(content, first, start);
- }
- else
- {
- length = start + last_length - (end + 1);
- content = malloc(sizeof(char) * length);
- strncpy(content, first, start);
+ if (selection->end_col == 0)
+ end = -1;
- strncpy(content + start, last + end + 1, last_length - (end + 1));
- }
+ length = start + last_length - (end + 1);
+ content = malloc(sizeof(char) * length);
+ strncpy(content, first, start);
+ if (last_length > 0)
+ strncpy(content + start, last + end + 1, last_length - (end + 1));
for (i = line->number; i > selection->start_line; i--)
elm_code_file_line_remove(pd->code->file, i);
file = elm_code_file_new(code);
elm_code_file_line_append(file, "text", 4, NULL);
elm_code_file_line_append(file, "TEXT", 4, NULL);
+ elm_code_file_line_append(file, "remove", 6, NULL);
win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
widget = elm_code_widget_add(win, code);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, NULL);
ck_assert_str_eq("text", text);
- ck_assert_int_eq(2, elm_code_file_lines_get(file));
+ ck_assert_int_eq(3, elm_code_file_lines_get(file));
elm_code_widget_selection_start(widget, 1, 3);
elm_code_widget_selection_end(widget, 2, 2);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, &length);
ck_assert_strn_eq("teXT", text, length);
+ ck_assert_int_eq(2, elm_code_file_lines_get(file));
+
+ elm_code_widget_selection_start(widget, 1, 5);
+ elm_code_widget_selection_end(widget, 2, 0);
+ elm_code_widget_selection_delete(widget);
+
+ line = elm_code_file_line_get(file, 1);
+ text = elm_code_line_text_get(line, &length);
+ ck_assert_strn_eq("teXTremove", text, length);
ck_assert_int_eq(1, elm_code_file_lines_get(file));
elm_code_free(code);
file = elm_code_file_new(code);
elm_code_file_line_append(file, "text", 4, NULL);
elm_code_file_line_append(file, "TEXT", 4, NULL);
+ elm_code_file_line_append(file, "remove", 6, NULL);
win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
widget = elm_code_widget_add(win, code);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, NULL);
ck_assert_str_eq("text", text);
- ck_assert_int_eq(2, elm_code_file_lines_get(file));
+ ck_assert_int_eq(3, elm_code_file_lines_get(file));
elm_code_widget_selection_start(widget, 2, 2);
elm_code_widget_selection_end(widget, 1, 3);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, &length);
ck_assert_strn_eq("teXT", text, length);
+ ck_assert_int_eq(2, elm_code_file_lines_get(file));
+
+ elm_code_widget_selection_start(widget, 2, 0);
+ elm_code_widget_selection_end(widget, 1, 5);
+ elm_code_widget_selection_delete(widget);
+
+ line = elm_code_file_line_get(file, 1);
+ text = elm_code_line_text_get(line, &length);
+ ck_assert_strn_eq("teXTremove", text, length);
ck_assert_int_eq(1, elm_code_file_lines_get(file));
elm_code_free(code);
elm_code_file_line_append(file, "text", 4, NULL);
elm_code_file_line_append(file, "remove", 6, NULL);
elm_code_file_line_append(file, "TEXT", 4, NULL);
+ elm_code_file_line_append(file, "delete", 6, NULL);
+ elm_code_file_line_append(file, "REMOVE", 6, NULL);
win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
widget = elm_code_widget_add(win, code);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, NULL);
ck_assert_str_eq("text", text);
- ck_assert_int_eq(3, elm_code_file_lines_get(file));
+ ck_assert_int_eq(5, elm_code_file_lines_get(file));
elm_code_widget_selection_start(widget, 1, 3);
elm_code_widget_selection_end(widget, 3, 2);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, &length);
ck_assert_strn_eq("teXT", text, length);
+ ck_assert_int_eq(3, elm_code_file_lines_get(file));
+
+ elm_code_widget_selection_start(widget, 1, 5);
+ elm_code_widget_selection_end(widget, 3, 0);
+ elm_code_widget_selection_delete(widget);
+
+ line = elm_code_file_line_get(file, 1);
+ text = elm_code_line_text_get(line, &length);
+ ck_assert_strn_eq("teXTREMOVE", text, length);
ck_assert_int_eq(1, elm_code_file_lines_get(file));
elm_code_free(code);
elm_code_file_line_append(file, "text", 4, NULL);
elm_code_file_line_append(file, "remove", 6, NULL);
elm_code_file_line_append(file, "TEXT", 4, NULL);
+ elm_code_file_line_append(file, "delete", 6, NULL);
+ elm_code_file_line_append(file, "REMOVE", 6, NULL);
win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
widget = elm_code_widget_add(win, code);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, NULL);
ck_assert_str_eq("text", text);
- ck_assert_int_eq(3, elm_code_file_lines_get(file));
+ ck_assert_int_eq(5, elm_code_file_lines_get(file));
elm_code_widget_selection_start(widget, 3, 2);
elm_code_widget_selection_end(widget, 1, 3);
line = elm_code_file_line_get(file, 1);
text = elm_code_line_text_get(line, &length);
ck_assert_strn_eq("teXT", text, length);
+ ck_assert_int_eq(3, elm_code_file_lines_get(file));
+
+ elm_code_widget_selection_start(widget, 3, 0);
+ elm_code_widget_selection_end(widget, 1, 5);
+ elm_code_widget_selection_delete(widget);
+
+ line = elm_code_file_line_get(file, 1);
+ text = elm_code_line_text_get(line, &length);
+ ck_assert_strn_eq("teXTREMOVE", text, length);
ck_assert_int_eq(1, elm_code_file_lines_get(file));
elm_code_free(code);