fix crash when deleting over a line ending

This commit is contained in:
Andy Williams 2015-05-30 20:46:34 +01:00
parent 10dc1c77bd
commit 86d5afb25d
2 changed files with 23 additions and 13 deletions

View File

@ -303,12 +303,12 @@ elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int col
else
chars = line->content;
while ((unsigned int) count < column && index <= (int) line->length)
while ((unsigned int) count < column && index < (int) line->length)
{
unicode = eina_unicode_utf8_next_get(chars, &index);
if (unicode == 0)
return line->length + 1;
return line->length;
else if (unicode == '\t')
count += elm_code_text_tabwidth_at_position(count, tabstop);
else

View File

@ -109,7 +109,7 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd)
{
Elm_Code_Line *line;
const char *old;
unsigned int old_length, length;
unsigned int old_length, start, end, length;
char *content;
if (pd->selection->end_col < pd->selection->start_col)
@ -117,12 +117,16 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd)
line = elm_code_file_line_get(pd->code->file, pd->selection->start_line);
old = elm_code_line_text_get(line, &old_length);
length = line->length - (pd->selection->end_col - pd->selection->start_col + 1);
content = malloc(sizeof(char) * length);
start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col,
pd->tabstop) - 1;
end = elm_code_line_text_position_for_column_get(line, pd->selection->end_col,
pd->tabstop) - 1;
length = line->length - (end - start + 1);
strncpy(content, old, pd->selection->start_col - 1);
strncpy(content + pd->selection->start_col - 1, old + pd->selection->end_col,
old_length - pd->selection->end_col);
content = malloc(sizeof(char) * length);
strncpy(content, old, start);
strncpy(content + start, old + end + 1,
old_length - (end + 1));
elm_code_line_text_set(line, content, length);
free(content);
}
@ -132,7 +136,7 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd)
{
Elm_Code_Line *line;
const char *first, *last;
unsigned int last_length, length, i;
unsigned int last_length, start, end, length, i;
char *content;
if (pd->selection->end_line <= pd->selection->start_line)
@ -140,13 +144,19 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd)
line = elm_code_file_line_get(pd->code->file, pd->selection->start_line);
first = elm_code_line_text_get(line, NULL);
start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col,
pd->tabstop) - 1;
line = elm_code_file_line_get(pd->code->file, pd->selection->end_line);
last = elm_code_line_text_get(line, &last_length);
length = pd->selection->start_col + last_length - (pd->selection->end_col + 1);
end = elm_code_line_text_position_for_column_get(line, pd->selection->end_col,
pd->tabstop) - 1;
length = start + last_length - (end + 1);
content = malloc(sizeof(char) * length);
strncpy(content, first, pd->selection->start_col - 1);
strncpy(content + pd->selection->start_col - 1, last + pd->selection->end_col,
last_length - pd->selection->end_col);
strncpy(content, first, start);
strncpy(content + start, last + end + 1,
last_length - (end + 1));
for (i = line->number; i > pd->selection->start_line; i--)
elm_code_file_line_remove(pd->code->file, i);