@@ -57,14 +57,14 @@ Clipboard& Clipboard::the()
57
57
Clipboard::DataAndType Clipboard::fetch_data_and_type () const
58
58
{
59
59
auto response = connection ().get_clipboard_data ();
60
+ auto type = response.mime_type ();
61
+ auto metadata = response.metadata ().entries ();
60
62
if (!response.data ().is_valid ())
61
- return {};
63
+ return { {}, type, metadata };
62
64
auto data = ByteBuffer::copy (response.data ().data <void >(), response.data ().size ());
63
65
if (data.is_error ())
64
66
return {};
65
67
66
- auto type = response.mime_type ();
67
- auto metadata = response.metadata ().entries ();
68
68
return { data.release_value (), type, metadata };
69
69
}
70
70
@@ -125,15 +125,18 @@ RefPtr<Gfx::Bitmap> Clipboard::DataAndType::as_bitmap() const
125
125
126
126
void Clipboard::set_data (ReadonlyBytes data, DeprecatedString const & type, HashMap<DeprecatedString, DeprecatedString> const & metadata)
127
127
{
128
+ if (data.is_empty ()) {
129
+ connection ().async_set_clipboard_data ({}, type, metadata);
130
+ return ;
131
+ }
132
+
128
133
auto buffer_or_error = Core::AnonymousBuffer::create_with_size (data.size ());
129
134
if (buffer_or_error.is_error ()) {
130
135
dbgln (" GUI::Clipboard::set_data() failed to create a buffer" );
131
136
return ;
132
137
}
133
138
auto buffer = buffer_or_error.release_value ();
134
- if (!data.is_empty ())
135
- memcpy (buffer.data <void >(), data.data (), data.size ());
136
-
139
+ memcpy (buffer.data <void >(), data.data (), data.size ());
137
140
connection ().async_set_clipboard_data (move (buffer), type, metadata);
138
141
}
139
142
0 commit comments