tweaks: simplify a pasting routine, modelling it after the injection one

This commit is contained in:
Benno Schulenberg 2022-09-26 16:02:28 +02:00
parent 162c213e7b
commit 034af70a65

View File

@ -182,16 +182,12 @@ void copy_the_answer(void)
void paste_into_answer(void) void paste_into_answer(void)
{ {
size_t pastelen = strlen(cutbuffer->data); size_t pastelen = strlen(cutbuffer->data);
char *fusion = nmalloc(strlen(answer) + pastelen + 1);
/* Concatenate: the current answer before the cursor, the first line answer = nrealloc(answer, strlen(answer) + pastelen + 1);
* of the cutbuffer, plus the rest of the current answer. */ memmove(answer + typing_x + pastelen, answer + typing_x,
strncpy(fusion, answer, typing_x); strlen(answer) - typing_x + 1);
strncpy(fusion + typing_x, cutbuffer->data, pastelen); strncpy(answer + typing_x, cutbuffer->data, pastelen);
strcpy(fusion + typing_x + pastelen, answer + typing_x);
free(answer);
answer = fusion;
typing_x += pastelen; typing_x += pastelen;
} }
#endif #endif