forked from enlightenment/efl
fix crash when deleting over a line ending
This commit is contained in:
parent
704cec0ae7
commit
906cfc9a2c
|
@ -303,12 +303,12 @@ elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int col
|
||||||
else
|
else
|
||||||
chars = line->content;
|
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);
|
unicode = eina_unicode_utf8_next_get(chars, &index);
|
||||||
|
|
||||||
if (unicode == 0)
|
if (unicode == 0)
|
||||||
return line->length + 1;
|
return line->length;
|
||||||
else if (unicode == '\t')
|
else if (unicode == '\t')
|
||||||
count += elm_code_text_tabwidth_at_position(count, tabstop);
|
count += elm_code_text_tabwidth_at_position(count, tabstop);
|
||||||
else
|
else
|
||||||
|
|
|
@ -109,7 +109,7 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd)
|
||||||
{
|
{
|
||||||
Elm_Code_Line *line;
|
Elm_Code_Line *line;
|
||||||
const char *old;
|
const char *old;
|
||||||
unsigned int old_length, length;
|
unsigned int old_length, start, end, length;
|
||||||
char *content;
|
char *content;
|
||||||
|
|
||||||
if (pd->selection->end_col < pd->selection->start_col)
|
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);
|
line = elm_code_file_line_get(pd->code->file, pd->selection->start_line);
|
||||||
old = elm_code_line_text_get(line, &old_length);
|
old = elm_code_line_text_get(line, &old_length);
|
||||||
length = line->length - (pd->selection->end_col - pd->selection->start_col + 1);
|
start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col,
|
||||||
content = malloc(sizeof(char) * length);
|
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);
|
content = malloc(sizeof(char) * length);
|
||||||
strncpy(content + pd->selection->start_col - 1, old + pd->selection->end_col,
|
strncpy(content, old, start);
|
||||||
old_length - pd->selection->end_col);
|
strncpy(content + start, old + end + 1,
|
||||||
|
old_length - (end + 1));
|
||||||
elm_code_line_text_set(line, content, length);
|
elm_code_line_text_set(line, content, length);
|
||||||
free(content);
|
free(content);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +136,7 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd)
|
||||||
{
|
{
|
||||||
Elm_Code_Line *line;
|
Elm_Code_Line *line;
|
||||||
const char *first, *last;
|
const char *first, *last;
|
||||||
unsigned int last_length, length, i;
|
unsigned int last_length, start, end, length, i;
|
||||||
char *content;
|
char *content;
|
||||||
|
|
||||||
if (pd->selection->end_line <= pd->selection->start_line)
|
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);
|
line = elm_code_file_line_get(pd->code->file, pd->selection->start_line);
|
||||||
first = elm_code_line_text_get(line, NULL);
|
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);
|
line = elm_code_file_line_get(pd->code->file, pd->selection->end_line);
|
||||||
last = elm_code_line_text_get(line, &last_length);
|
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);
|
content = malloc(sizeof(char) * length);
|
||||||
strncpy(content, first, pd->selection->start_col - 1);
|
strncpy(content, first, start);
|
||||||
strncpy(content + pd->selection->start_col - 1, last + pd->selection->end_col,
|
strncpy(content + start, last + end + 1,
|
||||||
last_length - pd->selection->end_col);
|
last_length - (end + 1));
|
||||||
|
|
||||||
for (i = line->number; i > pd->selection->start_line; i--)
|
for (i = line->number; i > pd->selection->start_line; i--)
|
||||||
elm_code_file_line_remove(pd->code->file, i);
|
elm_code_file_line_remove(pd->code->file, i);
|
||||||
|
|
Loading…
Reference in New Issue