From 3ea8b9298f75513388cde1aef7bb7af614cd3ec4 Mon Sep 17 00:00:00 2001 From: Seweryn Date: Sun, 26 Jul 2026 20:54:54 +0200 Subject: [PATCH] Refactor text insertion logic in rtext.c (#6022) Fixed nasty bug, text after insertion is deleted --- src/rtext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index d138f1f90..93e34a6f6 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1987,8 +1987,8 @@ char *TextInsert(const char *text, const char *insert, int position) // TODO: Allow copying data inserted up to maximum buffer size and stop for (int i = 0; i < position; i++) buffer[i] = text[i]; - for (int i = position; i < insertLen + position; i++) buffer[i] = insert[i - position]; - for (int i = (insertLen + position); i < (textLen + insertLen); i++) buffer[i] = text[i - insertLen]; + for (int i = 0; i < insertLen; i++) buffer[i+position] = insert[i]; + for (int i = position; i < textLen; i++) buffer[i+insertLen] = text[i]; buffer[textLen + insertLen] = '\0'; // Add EOL }