You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Convert line endings to CRLF in OS.set_clipboard() on Windows
Windows applications typically expect CRLF line endings in clipboard content. This closes #28439.
This commit is contained in:
@@ -1411,26 +1411,29 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
|||||||
|
|
||||||
void OS_Windows::set_clipboard(const String &p_text) {
|
void OS_Windows::set_clipboard(const String &p_text) {
|
||||||
|
|
||||||
|
// Convert LF line endings to CRLF in clipboard content
|
||||||
|
// Otherwise, line endings won't be visible when pasted in other software
|
||||||
|
String text = p_text.replace("\n", "\r\n");
|
||||||
|
|
||||||
if (!OpenClipboard(hWnd)) {
|
if (!OpenClipboard(hWnd)) {
|
||||||
ERR_EXPLAIN("Unable to open clipboard.");
|
ERR_EXPLAIN("Unable to open clipboard.");
|
||||||
ERR_FAIL();
|
ERR_FAIL();
|
||||||
};
|
};
|
||||||
EmptyClipboard();
|
EmptyClipboard();
|
||||||
|
|
||||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (p_text.length() + 1) * sizeof(CharType));
|
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * sizeof(CharType));
|
||||||
if (mem == NULL) {
|
if (mem == NULL) {
|
||||||
ERR_EXPLAIN("Unable to allocate memory for clipboard contents.");
|
ERR_EXPLAIN("Unable to allocate memory for clipboard contents.");
|
||||||
ERR_FAIL();
|
ERR_FAIL();
|
||||||
};
|
};
|
||||||
LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem);
|
LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem);
|
||||||
memcpy(lptstrCopy, p_text.c_str(), (p_text.length() + 1) * sizeof(CharType));
|
memcpy(lptstrCopy, text.c_str(), (text.length() + 1) * sizeof(CharType));
|
||||||
//memset((lptstrCopy + p_text.length()), 0, sizeof(CharType));
|
|
||||||
GlobalUnlock(mem);
|
GlobalUnlock(mem);
|
||||||
|
|
||||||
SetClipboardData(CF_UNICODETEXT, mem);
|
SetClipboardData(CF_UNICODETEXT, mem);
|
||||||
|
|
||||||
// set the CF_TEXT version (not needed?)
|
// set the CF_TEXT version (not needed?)
|
||||||
CharString utf8 = p_text.utf8();
|
CharString utf8 = text.utf8();
|
||||||
mem = GlobalAlloc(GMEM_MOVEABLE, utf8.length() + 1);
|
mem = GlobalAlloc(GMEM_MOVEABLE, utf8.length() + 1);
|
||||||
if (mem == NULL) {
|
if (mem == NULL) {
|
||||||
ERR_EXPLAIN("Unable to allocate memory for clipboard contents.");
|
ERR_EXPLAIN("Unable to allocate memory for clipboard contents.");
|
||||||
|
|||||||
Reference in New Issue
Block a user