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)"); line = geadline("(add)");
if (line == NULL) if (line == NULL)
return 1; return 1;
if (strcmp(line, ".\n") == 0) if (strcmp(line, ".") == 0)
{
[text + LOCATION_CURRENT_LINE] = [text + LOCATION_CURRENT_LINE] - 1;
return 0; return 0;
} tmp = galloc([text + LOCATION_LENGTH] + 1);
[text + LOCATION_LENGTH] = [text + LOCATION_LENGTH] + 1;
tmp = galloc([text + LOCATION_LENGTH]);
if (tmp == NULL) if (tmp == NULL)
return 1; return 1;
i = 0; i = 0;
j = 0; j = 0;
loop loop
{ {
if (i == [text + LOCATION_CURRENT_LINE]) if (i == [text + LOCATION_CURRENT_LINE] + 1 | i == [text + LOCATION_LENGTH])
{ {
[tmp + i] = line; [tmp + i] = line;
j++; j++;
} }
if (i + j == [text + LOCATION_LENGTH])
break;
[tmp + i + j] = [[text + LOCATION_ARRAY] + i]; [tmp + i + j] = [[text + LOCATION_ARRAY] + i];
if (i + j == [text + LOCATION_LENGTH] | i == [text + LOCATION_LENGTH])
break;
i++; i++;
} }
free([[text + LOCATION_ARRAY]]); puttab_str(tmp);
free([text + LOCATION_ARRAY]);
[text + LOCATION_ARRAY] = tmp; [text + LOCATION_ARRAY] = tmp;
[text + LOCATION_LENGTH] = [text + LOCATION_LENGTH] + 1;
[text + LOCATION_CURRENT_LINE] = [text + LOCATION_CURRENT_LINE] + 1; [text + LOCATION_CURRENT_LINE] = [text + LOCATION_CURRENT_LINE] + 1;
} }
} }