From ddb817a1af68523276a1b9c938808a62863f9b17 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 6 Jul 2023 08:32:34 -0700
Subject: [PATCH] Only clear the clipboard if setting empty text
---
src/video/SDL_clipboard.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c
index a95620cb5976..a2396bd4fe09 100644
--- a/src/video/SDL_clipboard.c
+++ b/src/video/SDL_clipboard.c
@@ -276,18 +276,13 @@ int SDL_SetClipboardText(const char *text)
return SDL_SetError("Video subsystem must be initialized to set clipboard text");
}
- if (SDL_ClearClipboardData() < 0) {
- return -1;
- }
+ if (text && *text) {
+ text_mime_types = SDL_GetTextMimeTypes(_this, &num_mime_types);
- if (!text || !*text) {
- /* All done! */
- return 0;
+ return SDL_SetClipboardData(SDL_ClipboardTextCallback, SDL_free, SDL_strdup(text), text_mime_types, num_mime_types);
+ } else {
+ return SDL_ClearClipboardData();
}
-
- 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)