diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index 677bf6ba28..6acd2f10e1 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -183,6 +183,23 @@ int utf8_get_format_code_arg_length(int codepoint) } } +void utf8_remove_formatting(utf8* string) { + utf8* readPtr = string; + utf8* writePtr = string; + + while (true) { + uint32 code = utf8_get_next(readPtr, &readPtr); + + if (code == 0) { + *writePtr = 0; + break; + } + else if (!utf8_is_format_code(code)) { + writePtr = utf8_write_codepoint(writePtr, code); + } + } +} + #pragma endregion void format_string_part_from_raw(char **dest, const char *src, char **args); diff --git a/src/localisation/localisation.h b/src/localisation/localisation.h index 30c6e7161a..324b0816c6 100644 --- a/src/localisation/localisation.h +++ b/src/localisation/localisation.h @@ -27,6 +27,7 @@ bool utf8_is_colour_code(int codepoint); bool utf8_should_use_sprite_for_codepoint(int codepoint); int font_sprite_get_codepoint_offset(int codepoint); int utf8_get_format_code_arg_length(int codepoint); +void utf8_remove_formatting(utf8* string); void format_string(char *dest, rct_string_id format, void *args); void format_string_raw(char *dest, char *src, void *args); diff --git a/src/platform/shared.c b/src/platform/shared.c index 4d1775b9f0..fd68199744 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -632,8 +632,13 @@ void platform_process_messages() } else if (e.key.keysym.sym == SDLK_v && (SDL_GetModState() & KEYBOARD_PRIMARY_MODIFIER)) { if (SDL_HasClipboardText()) { - utf8 *text = SDL_GetClipboardText(); + utf8* text = SDL_GetClipboardText(); + + utf8_remove_formatting(text); textinputbuffer_insert(&gTextInput, text); + + SDL_free(text); + window_update_textbox(); } } @@ -676,13 +681,11 @@ void platform_process_messages() break; } - // Entering formatting characters is not allowed - if (utf8_is_format_code(utf8_get_next(e.text.text, NULL))) { - break; - } + utf8* newText = e.text.text; - utf8 *newText = e.text.text; + utf8_remove_formatting(newText); textinputbuffer_insert(&gTextInput, newText); + console_refresh_caret(); window_update_textbox(); break;