mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibGUI: Avoid access to Clipboard server, clipboard text is never empty
The clipboard cannot reasonably contain the empty string. The clipboard can be empty (i.e. cleared), sure, but that this check was about whether the clipboard contained the empty string. This cannot easily happen for two reasons: - TextEditor GUI elements disable their copy actions when the selection is empty. - Clipboard::set_data, through which all text-copying operates, implicitly forbids empty strings, because Process::sys$anon_create forbids empty anonymous files. - Even if it were sent (e.g. by creating a non-empty anonymous file and sending it manually to the Clipboard server), it would not be received, because decode(Decoder&, Core::AnonymousBuffer&) goes through mmap() with a size of 0, which also is forbidden by the Kernel. In other words, if the clipboard is never the empty text, therefore checking this condition is pointless, and we can save a roundtrip to the Clipboard server.
This commit is contained in:
parent
c80dcc4671
commit
06f140a025
1 changed files with 2 additions and 2 deletions
|
@ -83,7 +83,7 @@ void TextEditor::create_actions()
|
|||
m_cut_action->set_enabled(false);
|
||||
m_copy_action->set_enabled(false);
|
||||
m_paste_action = CommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
||||
m_paste_action->set_enabled(is_editable() && Clipboard::the().mime_type().starts_with("text/") && !Clipboard::the().data().is_empty());
|
||||
m_paste_action->set_enabled(is_editable() && Clipboard::the().mime_type().starts_with("text/"));
|
||||
if (is_multi_line()) {
|
||||
m_go_to_line_action = Action::create(
|
||||
"Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
|
||||
|
@ -1882,7 +1882,7 @@ void TextEditor::cursor_did_change()
|
|||
|
||||
void TextEditor::clipboard_content_did_change(String const& mime_type)
|
||||
{
|
||||
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty());
|
||||
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/"));
|
||||
}
|
||||
|
||||
void TextEditor::set_document(TextDocument& document)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue