Only clear the clipboard if setting empty text

main
Sam Lantinga 2023-07-06 08:32:34 -07:00
parent f4bd17deee
commit ddb817a1af
1 changed files with 6 additions and 11 deletions

View File

@ -276,18 +276,13 @@ int SDL_SetClipboardText(const char *text)
return SDL_SetError("Video subsystem must be initialized to set clipboard text"); return SDL_SetError("Video subsystem must be initialized to set clipboard text");
} }
if (SDL_ClearClipboardData() < 0) { if (text && *text) {
return -1; text_mime_types = SDL_GetTextMimeTypes(_this, &num_mime_types);
return SDL_SetClipboardData(SDL_ClipboardTextCallback, SDL_free, SDL_strdup(text), text_mime_types, num_mime_types);
} else {
return SDL_ClearClipboardData();
} }
if (!text || !*text) {
/* All done! */
return 0;
}
text_mime_types = SDL_GetTextMimeTypes(_this, &num_mime_types);
return SDL_SetClipboardData(SDL_ClipboardTextCallback, SDL_free, SDL_strdup(text), text_mime_types, num_mime_types);
} }
char *SDL_GetClipboardText(void) char *SDL_GetClipboardText(void)