elm_code selection: complete multiline text get

ready for copy and cut functions
This commit is contained in:
Andy Williams 2015-03-25 22:55:32 +00:00
parent 514a796ac3
commit 87e2f2b0e8
2 changed files with 60 additions and 4 deletions

View File

@ -117,10 +117,11 @@ static char *
_elm_code_widget_selection_text_multi_get(Elm_Code_Widget_Data *pd)
{
Elm_Code_Line *line;
char *first, *last, *ret;
char *first, *last, *ret, *ptr;
const char *newline;
short newline_len;
int ret_len;
unsigned int row;
newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len);
@ -129,11 +130,34 @@ _elm_code_widget_selection_text_multi_get(Elm_Code_Widget_Data *pd)
line->length - pd->selection->start_col + 1);
line = elm_code_file_line_get(pd->code->file, pd->selection->end_line);
last = elm_code_line_text_substr(line, 0, pd->selection->end_col + 1);
last = elm_code_line_text_substr(line, 0, pd->selection->end_col);
ret_len = strlen(first) + strlen(last) + newline_len;
for (row = pd->selection->start_line + 1; row < pd->selection->end_line; row++)
{
line = elm_code_file_line_get(pd->code->file, row);
ret_len += line->length + newline_len;
}
ret = malloc(sizeof(char) * (ret_len + 1));
snprintf(ret, ret_len, "%s%s%s", first, newline, last);
snprintf(ret, strlen(first) + newline_len + 1, "%s%s", first, newline);
ptr = ret;
ptr += strlen(first) + newline_len;
for (row = pd->selection->start_line + 1; row < pd->selection->end_line; row++)
{
line = elm_code_file_line_get(pd->code->file, row);
if (line->modified)
snprintf(ptr, line->length + 1, "%s", line->modified);
else
snprintf(ptr, line->length + 1, "%s", line->content);
snprintf(ptr + line->length, newline_len + 1, "%s", newline);
ptr += line->length + newline_len;
}
snprintf(ptr, strlen(last) + 1, "%s", last);
free(first);
free(last);

View File

@ -65,7 +65,7 @@ START_TEST (elm_code_test_widget_selection_text_get)
}
END_TEST
START_TEST (elm_code_test_widget_selection_text_get_multiline)
START_TEST (elm_code_test_widget_selection_text_get_twoline)
{
Elm_Code *code;
Elm_Code_File *file;
@ -95,10 +95,42 @@ START_TEST (elm_code_test_widget_selection_text_get_multiline)
}
END_TEST
START_TEST (elm_code_test_widget_selection_text_get_multiline)
{
Elm_Code *code;
Elm_Code_File *file;
Elm_Code_Widget *widget;
Evas_Object *win;
char *selection;
elm_init(1, NULL);
code = elm_code_create();
file = elm_code_file_new(code);
elm_code_file_line_append(file, "test", 4, NULL);
elm_code_file_line_append(file, "test", 4, NULL);
elm_code_file_line_append(file, "test", 4, NULL);
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
widget = eo_add(ELM_CODE_WIDGET_CLASS, win,
elm_code_widget_code_set(code));
elm_code_widget_selection_start(widget, 1, 3);
elm_code_widget_selection_end(widget, 3, 2);
selection = elm_code_widget_selection_text_get(widget);
ck_assert_str_eq("st\ntest\nte", selection);
free(selection);
elm_code_free(code);
elm_shutdown();
}
END_TEST
void elm_code_test_widget_selection(TCase *tc)
{
tcase_add_test(tc, elm_code_test_widget_selection_set);
tcase_add_test(tc, elm_code_test_widget_selection_text_get);
tcase_add_test(tc, elm_code_test_widget_selection_text_get_twoline);
tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline);
}