Skip to content

Commit 0e00859

Browse files
committed
Fixed clipboard
Switch to using strictly 'text/plain' for text
1 parent bd03c66 commit 0e00859

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

BeefySysLib/platform/sdl/SdlBFApp.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ static int bfMouseBtnOf[4] = {0, 0, 2, 1}; // Translate SDL mouse buttons to wha
124124

125125
static const char* mimeTypes[] =
126126
{
127-
"text/plain;charset=utf-8",
128-
"text/vnd.beeflang.bf-text",
127+
"text/plain",
128+
"",
129129
"text/vnd.beeflang.file-list"
130130
};
131131

@@ -1067,11 +1067,12 @@ const char* SdlBFApp::GetClipboardFormat(const StringImpl& format)
10671067
{
10681068
if (format == "text" || format == "atext")
10691069
{
1070-
return "text/plain;charset=utf-8";
1070+
return "text/plain";
10711071
}
10721072
if (format == "bf_text")
10731073
{
1074-
return "text/vnd.beeflang.bf-text";
1074+
// This format is a hack to fix broken clipboards on Windows, not needed here
1075+
return "";
10751076
}
10761077
if (format == "code/file-list")
10771078
{
@@ -1085,6 +1086,9 @@ void* SdlBFApp::GetClipboardData(const StringImpl& format, int* size)
10851086
size_t outSize;
10861087
void* data = bf_SDL_GetClipboardData(GetClipboardFormat(format), &outSize);
10871088
*size = (int)outSize;
1089+
1090+
//printf("GetClipboardData %s: %.*s\n", GetClipboardFormat(format), *size, (const char*)data);
1091+
10881092
return data;
10891093
}
10901094

@@ -1107,25 +1111,29 @@ const void* SDLClipboardCallback(void* userData, const char* mimeType, size_t* o
11071111

11081112
void SdlBFApp::SetClipboardData(const StringImpl& format, const void* ptr, int size, bool resetClipboard)
11091113
{
1114+
StringImpl mime = StringImpl::MakeRef(GetClipboardFormat(format));
1115+
if (mime.empty())
1116+
{
1117+
//printf("SetClipboardData %s: Unsupported format\n", format.c_str());
1118+
return;
1119+
}
1120+
11101121
void* buffer = bf_SDL_malloc(size);
11111122
if (buffer == NULL)
11121123
{
11131124
bf_SDL_SetError("Out of memory for clipboard");
11141125
}
1115-
else
1126+
1127+
for (auto kv : *mSdlClipboardData)
11161128
{
1117-
StringImpl mime = StringImpl::MakeRef(GetClipboardFormat(format));
1129+
bf_SDL_free(kv.mValue);
1130+
}
1131+
bf_SDL_memcpy(buffer, ptr, size);
1132+
(*mSdlClipboardData)[mime] = buffer;
11181133

1119-
void* previous;
1120-
if (mSdlClipboardData->TryGetValue(mime, &previous))
1121-
{
1122-
bf_SDL_free(previous);
1123-
}
1124-
bf_SDL_memcpy(buffer, ptr, size);
1125-
(*mSdlClipboardData)[mime] = buffer;
1134+
//printf("SetClipboardData %s: %.*s\n", mime.c_str(), size, (const char*)ptr);
11261135

1127-
bf_SDL_SetClipboardData(SDLClipboardCallback, NULL, &mSdlClipboardData, mimeTypes, 3);
1128-
}
1136+
bf_SDL_SetClipboardData(SDLClipboardCallback, NULL, &mSdlClipboardData, mimeTypes, 3);
11291137
}
11301138

11311139
BFMenu* SdlBFWindow::AddMenuItem(BFMenu* parent, int insertIdx, const char* text, const char* hotKey, BFSysBitmap* bitmap, bool enabled, int checkState, bool radioCheck)

0 commit comments

Comments
 (0)