Skip to content

Commit d5418e8

Browse files
committed
Fix broken selection copying
1 parent fb9b809 commit d5418e8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

desktop_version/src/TextInput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ namespace TextInput
211211
return UTF8_substr(get_line(rect.y), rect.x, rect.x2);
212212
}
213213

214-
char* select_part_first_line = UTF8_substr(get_line(rect.y), rect.x, UTF8_total_codepoints(get_line(rect.y)) - rect.x);
214+
char* select_part_first_line = UTF8_substr(get_line(rect.y), rect.x, UTF8_total_codepoints(get_line(rect.y)));
215215
char* select_part_last_line = UTF8_substr(get_line(rect.y2), 0, rect.x2);
216216

217217
// Loop through the lines in between
@@ -221,7 +221,7 @@ namespace TextInput
221221
total_length += SDL_strlen(get_line(i)) + 1;
222222
}
223223

224-
char* select_part = (char*)SDL_malloc(total_length);
224+
char* select_part = (char*)SDL_malloc(total_length + 1);
225225
strcpy(select_part, select_part_first_line);
226226
strcat(select_part, "\n");
227227
for (int i = rect.y + 1; i < rect.y2; i++)
@@ -230,6 +230,7 @@ namespace TextInput
230230
strcat(select_part, "\n");
231231
}
232232
strcat(select_part, select_part_last_line);
233+
strcat(select_part, "\0");
233234

234235
SDL_free(select_part_first_line);
235236
SDL_free(select_part_last_line);

0 commit comments

Comments
 (0)