1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibVT: Make paste access to Clipboard atomic

This avoids data race issues and saves a synchronous request to
ClipboardServer.
This commit is contained in:
Ben Wiederhake 2021-11-20 14:20:30 +01:00 committed by Linus Groh
parent b6419f2cf2
commit ff17f6877a

View file

@ -752,13 +752,12 @@ void TerminalWidget::paste()
if (m_ptm_fd == -1) if (m_ptm_fd == -1)
return; return;
auto mime_type = GUI::Clipboard::the().mime_type(); auto [data, mime_type, _] = GUI::Clipboard::the().data_and_type();
if (!mime_type.starts_with("text/")) if (!mime_type.starts_with("text/"))
return; return;
auto text = GUI::Clipboard::the().data(); if (data.is_empty())
if (text.is_empty())
return; return;
send_non_user_input(text); send_non_user_input(data);
} }
void TerminalWidget::copy() void TerminalWidget::copy()
@ -1167,7 +1166,8 @@ void TerminalWidget::update_copy_action()
void TerminalWidget::update_paste_action() void TerminalWidget::update_paste_action()
{ {
m_paste_action->set_enabled(GUI::Clipboard::the().mime_type().starts_with("text/") && !GUI::Clipboard::the().data().is_empty()); auto [data, mime_type, _] = GUI::Clipboard::the().data_and_type();
m_paste_action->set_enabled(mime_type.starts_with("text/") && !data.is_empty());
} }
void TerminalWidget::set_color_scheme(StringView name) void TerminalWidget::set_color_scheme(StringView name)