summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-11-20 14:59:58 +0100
committerLinus Groh <mail@linusgroh.de>2021-11-21 11:49:06 +0000
commitc80dcc46719583d8cf3ec2d57d349e71cd998f04 (patch)
treee196da22572710a72ef6c77634a592f45b1ebc97 /Userland/Libraries/LibGUI
parent81128c5100894141db88aa1b2e9eb0e981b49fa6 (diff)
downloadserenity-c80dcc46719583d8cf3ec2d57d349e71cd998f04.zip
LibGUI: Make paste access to Clipboard atomic
This avoids data race issues and saves a synchronous request to the ClipboardServer.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 8ad2bd30dd..c69bb69f8a 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -1453,18 +1453,17 @@ void TextEditor::paste()
if (!is_editable())
return;
- if (!Clipboard::the().mime_type().starts_with("text/"))
+ auto [data, mime_type, _] = GUI::Clipboard::the().data_and_type();
+ if (!mime_type.starts_with("text/"))
return;
- auto paste_text = Clipboard::the().data();
-
- if (paste_text.is_empty())
+ if (data.is_empty())
return;
- dbgln_if(TEXTEDITOR_DEBUG, "Paste: \"{}\"", String::copy(paste_text));
+ dbgln_if(TEXTEDITOR_DEBUG, "Paste: \"{}\"", String::copy(data));
TemporaryChange change(m_automatic_indentation_enabled, false);
- insert_at_cursor_or_replace_selection(paste_text);
+ insert_at_cursor_or_replace_selection(data);
}
void TextEditor::defer_reflow()