api/system: fix newlines returned by get_clipboard (#1788)

This commit is contained in:
Takase 2024-05-24 04:19:15 +08:00 committed by GitHub
parent 5549c0bd29
commit e74cee1419
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View File

@ -830,7 +830,14 @@ static int f_mkdir(lua_State *L) {
static int f_get_clipboard(lua_State *L) {
char *text = SDL_GetClipboardText();
if (!text) { return 0; }
#ifdef _WIN32
// on windows, text-based clipboard formats must terminate with \r\n
// we need to convert it to \n for Lite XL to read them properly
// https://learn.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats
luaL_gsub(L, text, "\r\n", "\n");
#else
lua_pushstring(L, text);
#endif
SDL_free(text);
return 1;
}