commit 034af70a652291c043c428172ce83887205bc835
parent 162c213e7b68d91d47cce4012249719b2700d6d5
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 26 Sep 2022 16:02:28 +0200
tweaks: simplify a pasting routine, modelling it after the injection one
Diffstat:
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/prompt.c b/src/prompt.c
@@ -182,16 +182,12 @@ void copy_the_answer(void)
void paste_into_answer(void)
{
size_t pastelen = strlen(cutbuffer->data);
- char *fusion = nmalloc(strlen(answer) + pastelen + 1);
- /* Concatenate: the current answer before the cursor, the first line
- * of the cutbuffer, plus the rest of the current answer. */
- strncpy(fusion, answer, typing_x);
- strncpy(fusion + typing_x, cutbuffer->data, pastelen);
- strcpy(fusion + typing_x + pastelen, answer + typing_x);
+ answer = nrealloc(answer, strlen(answer) + pastelen + 1);
+ memmove(answer + typing_x + pastelen, answer + typing_x,
+ strlen(answer) - typing_x + 1);
+ strncpy(answer + typing_x, cutbuffer->data, pastelen);
- free(answer);
- answer = fusion;
typing_x += pastelen;
}
#endif