fix: cmd_add add line after current line

This commit is contained in:
starnakin 2023-07-26 14:15:59 +02:00
parent 9d7d6f7a65
commit 896376887e

View File

@ -9,31 +9,29 @@ cmd_add(text, args)
line = geadline("(add)");
if (line == NULL)
return 1;
if (strcmp(line, ".\n") == 0)
{
[text + LOCATION_CURRENT_LINE] = [text + LOCATION_CURRENT_LINE] - 1;
if (strcmp(line, ".") == 0)
return 0;
}
[text + LOCATION_LENGTH] = [text + LOCATION_LENGTH] + 1;
tmp = galloc([text + LOCATION_LENGTH]);
tmp = galloc([text + LOCATION_LENGTH] + 1);
if (tmp == NULL)
return 1;
i = 0;
j = 0;
loop
{
if (i == [text + LOCATION_CURRENT_LINE])
if (i == [text + LOCATION_CURRENT_LINE] + 1 | i == [text + LOCATION_LENGTH])
{
[tmp + i] = line;
j++;
}
if (i + j == [text + LOCATION_LENGTH])
break;
[tmp + i + j] = [[text + LOCATION_ARRAY] + i];
if (i + j == [text + LOCATION_LENGTH] | i == [text + LOCATION_LENGTH])
break;
i++;
}
free([[text + LOCATION_ARRAY]]);
puttab_str(tmp);
free([text + LOCATION_ARRAY]);
[text + LOCATION_ARRAY] = tmp;
[text + LOCATION_LENGTH] = [text + LOCATION_LENGTH] + 1;
[text + LOCATION_CURRENT_LINE] = [text + LOCATION_CURRENT_LINE] + 1;
}
}