Browse Source

LibVT: Make paste access to Clipboard atomic

This avoids data race issues and saves a synchronous request to
ClipboardServer.
Ben Wiederhake 3 năm trước cách đây
mục cha
commit
ff17f6877a
1 tập tin đã thay đổi với 5 bổ sung5 xóa
  1. 5 5
      Userland/Libraries/LibVT/TerminalWidget.cpp

+ 5 - 5
Userland/Libraries/LibVT/TerminalWidget.cpp

@@ -752,13 +752,12 @@ void TerminalWidget::paste()
     if (m_ptm_fd == -1)
         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/"))
         return;
-    auto text = GUI::Clipboard::the().data();
-    if (text.is_empty())
+    if (data.is_empty())
         return;
-    send_non_user_input(text);
+    send_non_user_input(data);
 }
 
 void TerminalWidget::copy()
@@ -1167,7 +1166,8 @@ void TerminalWidget::update_copy_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)